Announcement

Collapse
No announcement yet.

ComboBox and CONTROL GET TEXT

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ComboBox and CONTROL GET TEXT

    I have been using
    DIM a$
    COMBOBOX GET TEXT hDlg, 301 TO a$
    up untill now. I can create the ComboBox, Add items to it, select which item goes up top, and retrieve the item up top.

    Now I want to retireive ALL the strings in the ComboBox. The manual says
    CONTROL GET TEXT hDlg, 301 TO a$
    will do it. Then I
    REPLACE CHR$(0) WITH "," IN a$
    and PARSE$ out all the strings.

    The concept is great ...
    The problem is that a$ is empty???
    If I simply substitute
    COMBOBOX GET TEXT hDlg, 301 TO a$
    then a$ returns the top item fine.

    I have read poffs 20x and I am sure i am doing everything right, so why doesnt it work?



    ------------------
    Kind Regards
    Mike

  • #2
    That appears to be an error in the doc's - CONTROL GET TEXT on a combo box does not retrieve the string list.

    The solution is to use CONTROL SEND with discrete Combobox messages...

    Use %CB_GETCOUNT to get the item count, then set up a loop with %CB_GETLBTEXT.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      aaaaaaaah!
      Well that accounts for that.

      I have gotten these to work:
      COMBOBOX GET TEXT hDlg, 301 TO TempStr
      CONTROL SEND hDlg, 301, %CB_GETCURSEL, 0, 0 TO i
      CONTROL SEND hDlg, 301, %CB_GETCOUNT, 0, 0 TO NumItems

      But I cant get %CB_GETLBTEXT to work:

      This is obviously wrong:
      LOCAL zText AS STRING * 255
      CONTROL SEND hDlg, 301, %CB_GETLBTEXT, i, 0 TO ztext

      in the forum there are very few examples. One has:
      SendMessage hComboBox, %CB_GETLBTEXT, Index, VARPTR(zText)
      but this does not work for me
      SENDMESSAGE 301, %CB_GETLBTEXT, i, VARPTR(zText)
      TempStr = zText
      TempStr is empty

      I searched all the forums again and the downloads and ...
      all the examples just get the top item (CURSEL)
      Anyone got a working EXAMPLE of retrieveing ALL the text from a combobox? anything?




      ------------------
      Kind Regards
      Mike

      Comment


      • #4

        Mike..

        SendMessage requires the handle to destination window. You are sending
        301 which is your control identifier. Use GetDlgItem to retrieve the
        correct handle..

        hcomboBox = GetDlgItem(hWnd, 301)

        SENDMESSAGE hcomboBox, %CB_GETLBTEXT, i, VARPTR(zText)


        ------------------
        Jim..
        [email protected]
        Jim..

        Comment


        • #5
          Jim,
          thx sooooo much. that works. Without a full and complete education in Win API these things that seem obvious are a eral problem for us in the learning process.

          I have wasted about 4 hrs on this very simple but very frustrating problem!

          I wrote a workaround that runs fine. It moves each item in turn up to the top or Current selection and then retrieves the text (commented out) but I can now use the better way of getting the text directly.

          thx again

          LOCAL i AS LONG, Pos AS LONG, NumItems AS LONG, MatchStr AS STRING, zText AS STRING * 255

          CONTROL SEND hDlg, 301, %CB_GETCOUNT, 0, 0 TO NumItems
          FOR i = 1 TO NumItems ' 0 is the first one and is empty unless selected?
          SENDMESSAGE GETDLGITEM(hDlg, 301), %CB_GETLBTEXT, i-1, VARPTR(zText)
          tempStr = zText
          'COMBOBOX SELECT hDlg, 301, i
          'COMBOBOX GET TEXT hDlg, 301 TO TempStr
          Pos = i
          MatchStr = RIGHT$(TempStr, 3)
          IF INSTR(MainStr, MatchStr) > 0 THEN i = 999999 ' terminate the search
          NEXT
          COMBOBOX SELECT hDlg, 301, Pos ' Move it up to the top so user can see it


          ------------------
          Kind Regards
          Mike

          Comment


          • #6
            Mike..

            To be consistent and use all DDT.. The following will work..

            CONTROL SEND hDlg, 301, %CB_GETLBTEXT, i-1, VARPTR(zText)



            ------------------
            Jim..
            [email protected]
            Jim..

            Comment

            Working...
            X