Announcement

Collapse
No announcement yet.

Getting and keeping text from a Combobox

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

  • Fred Buffington
    replied
    Thanks Lance, That worked
    I changed the first part of the case 114 to:
    Code:
        CASE 114
           COMBOBOX GET TEXT CBHNDL, 114 TO UserName
           IF UserName="" THEN
    '       SELECT CASE CBCTLMSG
    '         CASE %CBN_EDITCHANGE
               CONTROL GET TEXT CBHNDL, 114 TO UserName
    '         END SELECT
           END IF
             coidx$=UserName
    Now I can eliminate the lower textbox which is what i wanted to
    accomplish.

    I figured it was something simple.


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

    Leave a comment:


  • Scott Turchin
    replied
    If the user selected an option out of the combo box, then I did this, and did the CBN_SELENDOK to verify.

    Code:
            Case %IDCOMBOBOX
                  If LoWrd(CbCtlMsg) = %CBN_SELENDOK Then
                       ComboBox Get Text hDlg ,%IDCOMBOBOX To g_szDestURL
                       Array Scan HistArray(1), = g_szDestURL, To HistIndex
                       ComboBox Select hDlg, %IDCOMBOBOX, HistIndex
                       g_Result = ShellExecute(ByVal %NULL, "open", g_szDestURL + Chr$(0), ByVal %NULL, ByVal %NULL,%SW_SHOWMAXIMIZED)
    
                   End If
                   Function = 1
                   Exit Function
    
    
    '
    '
    '
    '
    But if they were just typing, then I did this, (it was subclassed to pull out $CR)
    'In Dialog Proc:
        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
    
    
    '
    '
    '
    '
    After dialog exited, (Right after DIALOG SHOW hDlg Call DialogProc) I did this:
    If OldCBProc Then SetWindowLong hCombo, %GWL_WNDPROC, OLDCBProc
    
    
    Now you have a subclassed combo box...
    
    
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' 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 Turchin
    MCSE, MCP+I
    Computer Creations Software
    http://www.tngbbs.com/ccs

    Leave a comment:


  • Lance Edmonds
    replied
    Sounds straight forward, unless I'm missing something here...

    Use <U>COMBOBOX GET TEXT</U> to get the SELected item text.

    If this gives you an empty (null) string, use <U>CONTROL GET TEXT</U> to get the typed text in the edit portion of the combobox.



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

    Leave a comment:


  • Fred Buffington
    replied
    Bern, sorry for any confusion.
    The id's are basically subdirectory names where the company
    information (accounting info) is kept. Client in this respect
    is not the computer use of the term client but the CPA (Certified
    Public Accountant) use of the term, analogous more to another
    business's "customer" in a general sense.

    the company file, called "client" is kept in this directory and
    is opened in the callback routine to get the "company name" and
    display it as a label on the dialog.

    As I said, it all works fine with one exception. I cannot do both
    enter a client id (subdirectory name) ANB select a client ID from
    the combobox. That is, with the combobox get text statment I can
    select a client id, and the Getcli function retains it when
    the OK button is pressed, (if i type it in and have the control
    get text - the company (i.e. client) name displays in the label
    just finebut the getcli function does not have the value typed
    for coidx$ in it when the OK button is pressed. But if i rem out
    the combobox get text, then i can type it in and the getcli
    function does keep the value typed for coidx$.

    What I want to do is allow either the typing in of a valid subdirectory
    name or selection from the combobox, have it retain the value
    either typed or selected with a mouse click and therefore
    eliminate the need for a separate textbox.

    Does that clear things up a bit.




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

    Leave a comment:


  • Bern Ertl
    replied
    Fred,

    Maybe its just me, but I found your description of the
    problem confusing. Is the company name different from
    the company ID? Are you trying to maintain a match between
    an index and an array of text? I think some code might be
    useful....



    ------------------
    Bernard Ertl

    Leave a comment:


  • Fred Buffington
    replied
    Well keith the display is not a problem so im not sure that will
    help.

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

    Leave a comment:


  • Keith Waters
    replied
    Fred

    I don't know whether this helps, but I've been doing something that sounds similar with a combo box on a toolbar. I'm doing SDK style programming as opposed to DDT.

    I found that the only reliable way of making the combo field display what it should, was to explicitly set its contents. I'm actually using the following call to do that.

    Code:
        CALL Edit_SetText(tb_hWndCombo, sText$)
    Keith


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

    Leave a comment:


  • Fred Buffington
    started a topic Getting and keeping text from a Combobox

    Getting and keeping text from a Combobox

    I have a combobox and a textbox in a small dialog (DDT)
    The user can Select a Company ID from the combobox
    or enters one in the textbox.
    If you select one from the combobox, it reads the company
    name and sets a label control to that company name.

    This all works just fine.
    I thought however, why not eliminate the text box and allow
    entry in the combobox too.
    So, I added the control get text statement to the callback
    routine within a select case CBCTLMSG >case %CBN_EDITCHANGE
    in addition to the combobox get text statement.
    Once I have typed in a valid ID in the combobox, the company
    name shows up like it should but the company ID is not kept
    when i exit. If I select from the combobox or type it in the
    textbox it does retain it as before.
    It's got to be something simple.
    I guess I should show the code though.

    *** ok I found that if I rem the combobox get text statement
    *** that it retains the text that i type in but then i can
    *** no longer select it from the list.

    Code:
    .
    .
    GLOBAL UserName as String
    GLOBAL Coidx$
    GLOBAL abort%
    CALLBACK FUNCTION propcallback
     LOCAL getnam AS clityp
     
     CID&=CBCTL
     SELECT CASE cid&
        CASE 103
            DIALOG END hDlg2,1
            propcallback=1
        CASE 113
          DIALOG END hDlg2,1
          abort%=1
        CASE 114
           COMBOBOX GET TEXT CBHNDL, 114 TO UserName
           
           SELECT CASE CBCTLMSG
             CASE %CBN_EDITCHANGE
               CONTROL GET TEXT CBHNDL, 114 TO UserName
             END SELECT
             coidx$=UserName
           
           IF coidx$<>prior_coid$ THEN
             OPEN coidx$+"\client" FOR RANDOM ACCESS READ WRITE AS #9 LEN=LEN(getnam)
             GET #9,1,getnam
             xnam$=getnam.clnam
             CONTROL SET TEXT hDlg2,120,RTRIM$(xnam$)
             CLOSE #9
             prior_coid$=coidx$
          END IF
        CASE 117
             CONTROL GET TEXT CBHNDL, 117 TO UserName
             coidx$=UserName
        END SELECT
        EXIT FUNCTION
    END FUNCTION
    
    FUNCTION GETCLI() export as string
     .
     .
     .
       DIALOG  NEW 0,dTitle$,,,200,150,%DS_3DLOOK,%WS_EX_LEFT TO hDlg2
       CONTROL ADD LABEL, hDlg2,119,"  Select",10,33,40,12
       CONTROL ADD LABEL, hdlg2,102,"Client ID:",10,47,40,12
       CONTROL ADD FRAME, hdlg2,116,"",8,4,181,84,,%WS_EX_WINDOWEDGE
       CONTROL ADD BUTTON, hDLG2,103,"OK",70,116,20,16,%BS_CENTER,%WS_EX_LEFT
       CONTROL ADD BUTTON, hDLG2,113,"CANCEL",100,116,40,16,%BS_CENTER,%WS_EX_LEFT
       CONTROL ADD LABEL, hDlg2,120,"Company Name displays here",12,74,175,12,%SS_CENTER
       CONTROL ADD COMBOBOX, hDlg2,114,directories$(),70,14,60,60,%WS_VSCROLL ''AND %CBS_DROPDOWN
       COMBOBOX SELECT hDlg2, 114, 1
       CONTROL ADD TEXTBOX, hDlg2, 117,coid$,70,96,50,14
       CONTROL ADD LABEL, hDlg2, 118,"Or Enter it:",10,98,40,14
       DIALOG SHOW MODAL hDLG2, CALL propcallback
       IF abort%=0 THEN
          FUNCTION=coidx$
       ELSE
          FUNCTION=""
          abort%=0
       END IF
    END FUNCTION
                                                                                                                                                                                                                                                                   _

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


    [This message has been edited by Fred Buffington (edited September 19, 2001).]
Working...
X