Announcement

Collapse
No announcement yet.

Problems with Combobox

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

  • Problems with Combobox

    Please help! I cannot get my program to recognize text input from the user into the text box of a combobox. Here's my code:

    #COMPILE EXE
    #INCLUDE "DDT.INC"
    $REGISTER NONE

    %IDOK = 1
    %IDCANCEL = 2
    %IDUSER = 3
    %BS_DEFAULT = 1

    '------------------------------------------------------------------------------
    ' Global variable to recieve the user name

    GLOBAL ComboText$

    '------------------------------------------------------------------------------

    CALLBACK FUNCTION OkButton()

    COMBOBOX GET TEXT CBHNDL, %IDUSER TO ComboText$
    DIALOG END CBHNDL, 1

    END FUNCTION

    CALLBACK FUNCTION CancelButton()

    DIALOG END CBHNDL, 0

    END FUNCTION

    FUNCTION DoIt&()

    LOCAL hDlg&, Result&

    ' ** Create a new dialog template
    DIALOG NEW 0, "ComboBox Test", ,, 200, 82, 0, 0 TO hDlg&

    ' ** Add controls to it
    CONTROL ADD LABEL, hDlg&, -1, "&User Name", 14, 14, 36, 12,
    CONTROL ADD COMBOBOX, hDlg&, %IDUSER, , 60, 12, 120, 100, %CBS_DROPDOWN OR %WS_VSCROLL OR %WS_TABSTOP OR %CBS_HASSTRINGS
    CONTROL ADD BUTTON, hDlg&, %IDOK, "&OK", 34, 60, 40, 14, %BS_DEFAULT CALL OkButton
    CONTROL ADD BUTTON, hDlg&, %IDCANCEL,"&Cancel", 124, 60, 40, 14, 0 CALL CancelButton

    ' Clear the combo box list
    COMBOBOX RESET hDlg&, %IDUSER
    COMBOBOX ADD hDlg&, %IDUSER, "Joe Blow"
    COMBOBOX ADD hDlg&, %IDUSER, "John Doe"

    ' ** Display the dialog
    DIALOG SHOW MODAL hDlg& TO Result&

    FUNCTION = Result&

    END FUNCTION

    '------------------------------------------------------------------------------

    FUNCTION PBMAIN () AS LONG

    IF DoIt&() THEN MSGBOX ">"+ComboText$+"<"

    END FUNCTION

    Bernard Ertl
    InterPlan Systems

  • #2
    Try CONTROL GET TEXT.. instead of COMBOBOX.. and it will work.


    ------------------

    Comment


    • #3
      Thank you! Wow that was fast!

      I'm able to continue with my code now.

      Note to PB: Why doesn't the COMBOBOX GET TEXT statement work? If CONTROL GET TEXT has the exact same functionality, why include it at all?

      Thanks again for the super fast problem solving....


      ------------------
      Bernard Ertl
      InterPlan Systems

      Comment


      • #4
        I always thought that american guys have problems with English.

        From Pb.Hlp

        COMBOBOX GET TEXT hDlg&, id& TO text$
        Retrieves the default text from a combo box.

        The default selection can be done
        a) by COMBOBOX SELECT hDlg&, id&, pos&
        b) by selecing an item from the list in run-time

        If to type something in textbox - nothing selected.

        ------------------
        E-MAIL: [email protected]

        Comment


        • #5
          The combo listbox is exactly what it says, a combination of a
          listbox and an edit control. That is why there are two different
          sets of commands for it, so to speak.

          CONTROL GET TEXT is most likely a wrapper for two SendMessage calls,
          WM_GETTEXTLENGTH and WM_GETTEXT, which also can be used.

          Same thing with COMBOBOX GET TEXT, which I guess is a wrapper for
          the CB_GETCURSEL and CB_GETLBTEXT messages.

          The PB helpfile isn't very clear on this. Like Semen pointed out,
          it only tells us it "retieves the default text", whatever that
          means. "Selected item's text" would have been better, IMHO..

          A good tip. In Win32api.hlp all controls are explained. If you
          for example look up "Combo Boxes" and then use the Right Arrow
          button to turn pages, there are a lot of useful info about it
          there, including description on how to do ownerdrawn and
          subclassed controls, etc. Lots of useful info there.


          ------------------


          [This message has been edited by Borje Hagsten (edited January 17, 2001).]

          Comment


          • #6
            Da Semen, I read that ("DEFAULT") in the docs, but I did not understand what it meant. It is not explained. As this is all new to me, I assumed that it meant whatever was in the text box.

            What would be the purpose of checking for the default assuming it wasn't already known when (it seems to me) the actual (user) selection is really what one is interested in?

            Thanks again,
            Bernard Ertl

            ------------------
            Bernard Ertl
            InterPlan Systems

            Comment


            • #7
              In the majority of cases, retrieving the text in the edit control portion of the combobox is all that is often required, however, retrieving the default text could be useful for assisting in statusbar information as selections are made, or in a whole host of other situations like reading information from a child dialog, etc. When it comes to using control's, there is nothing more creative and inventive than a GUI programmer who wants to add a "twist" to their app's GUI interface.

              Anyway, this has been an interesting thread... I'll be asking the Documentation Dept to clarify the relevent text in the next update to the documentation.

              Thanks for pointing it out!

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

              Comment


              • #8
                Lance,

                While you are at it, could you put in a request to the Docs Dept. to include the "See also" section which they included in the PB 3.x (DOS) docs? I found them indispensible when I couldn't remember the exact function/sub I was looking for. For the new DDT functions, a section like that would definately help (me at least).

                Thanks.

                Bernard Ertl

                ------------------
                Bernard Ertl
                InterPlan Systems

                Comment


                • #9
                  Just for GP, I was peruzing a piece of code of mine that uses the combo box extensively and found that ComboBox GetText does in fact work...weird.


                  Code:
                          Case %IDCOMBOBOX
                                If LoWrd(CbCtlMsg) = %CBN_SELENDOK Then
                                     ComboBox Get Text hDlg ,%IDCOMBOBOX To g_szDestURL 'Destination URL
                                     Array Scan HistArray(1), = g_szDestURL, To HistIndex 'Get index # for history file
                                     ComboBox Select hDlg, %IDCOMBOBOX, HistIndex 'Now select it manually to make it show
                                     g_Result = ShellExecute(ByVal %NULL, "open", g_szDestURL + Chr$(0), ByVal %NULL, ByVal %NULL,%SW_SHOWMAXIMIZED) 'Now launch the URL
                                 End If
                                 Function = 1
                                 Exit Function
                  ------------------
                  Scott
                  mailto:[email protected][email protected]</A>
                  Scott Turchin
                  MCSE, MCP+I
                  http://www.tngbbs.com
                  ----------------------
                  True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                  Comment


                  • #10
                    I subclassed mine, perhaps that has something to do with it?

                    Code:
                    Dialog New 0, g_szMine,g_Top, g_Left,300,30, %WS_MINIMIZEBOX Or %WS_CAPTION Or %WS_SYSMENU Or %WS_EX_LEFT  To hDlg
                    Control Add ComboBox, hDlg, %IDCOMBOBOX, HistArray(), 5, 1, 290,120, %CBS_DROPDOWN Or %WS_TABSTOP
                    Dialog Send hDlg, %WM_SETICON, %ICON_BIG, hIcon
                    Menu Attach hMenu, hDlg
                    Dialog Show Modal hDlg Call DialogProc To g_Result
                    
                    Array Scan HistArray(1), = "", To lCount
                    If OldCBProc Then SetWindowLong hCombo, %GWL_WNDPROC, OLDCBProc
                     
                    
                    'In the Main Window callback:
                    
                        Case %WM_INITDIALOG 
                            Control Handle hDlg, %IDCOMBOBOX To hCombo   'Sub-class, to trap keyboard events
                            OldCBProc = SetWindowLong(hCombo, %GWL_WNDPROC, CodePtr(CBProc))
                            ComboBox Select hDlg, %IDCOMBOBOX, 1   
                    
                    
                    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                    ' Combobox subclass
                    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                    Function CBProc(ByVal hWnd As Long, ByVal wMsg As Long, _
                                    ByVal wParam As Long, ByVal lParam As Long) As Long
                    Local KeyNum As Long
                    
                    Select Case wMsg
                        Case %WM_KEYDOWN
                        Case %WM_CHAR
                        Case %WM_KEYUP
                        Case %CB_GETDROPPEDSTATE 'get enter key from a %CBS_DROPDOWN combo
                             Control Get Text hDlg ,%IDCOMBOBOX To g_szDestURL
                             Incr lCount
                             HistArray(lCount) = g_szDestURL 'Add to array to write to disk.
                    '         ComboBox Add hDlg, %IDCOMBOBOX, g_szDestURL
                             g_Result = ShellExecute(ByVal %NULL, "open", g_szDestURL + Chr$(0), ByVal %NULL, ByVal %NULL,%SW_SHOWMAXIMIZED)
                    End Select
                    Function = CallWindowProc(OldCBProc, hWnd, wMsg, wParam, lParam)
                    End Function
                    ------------------
                    Scott
                    mailto:[email protected][email protected]</A>
                    Scott Turchin
                    MCSE, MCP+I
                    http://www.tngbbs.com
                    ----------------------
                    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                    Comment


                    • #11
                      Scott,

                      I'm no expert by any means, by from my limited testing, it appears that the COMBOBOX GET TEXT function only retrieves text if the user makes a selection from the list box. If the user types something in the text box, it does not recognize it.

                      I noticed that you used the CONTROL GET TEXT in your subclassing procedure. That's the function which Semen pointed out will correctly retrieve the edit box text.

                      Bernard Ertl



                      ------------------
                      Bernard Ertl
                      InterPlan Systems

                      Comment


                      • #12
                        Good point, whomever gave me the code (Semen?) may have already learned thhat.
                        The subclass is definitely for when a user enters text and hit enters.




                        ------------------
                        Scott
                        mailto:[email protected][email protected]</A>
                        Scott Turchin
                        MCSE, MCP+I
                        http://www.tngbbs.com
                        ----------------------
                        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                        Comment

                        Working...
                        X