Results 1 to 6 of 6

Thread: ComboBox auto complete word

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    I want to know if there is a property or something to make my combo box autocomplete the word I am typing with what it finds in the list...
    Or am I doing something wrong ?

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Sure thing:


    Code:
    Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const CB_FINDSTRING = &H14C
    
    
    Private Sub Combo1_Change()
        Dim lRetIndex As Long
        
        lRetIndex = SendMessageStr(Combo1.hwnd, CB_FINDSTRING, -1, ByVal Combo1.Text)
        If lRetIndex >= 0 Then Combo1.ListIndex = lRetIndex
    End Sub

    Regards,

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

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Thanks for the help!

    but it seems that it only searches for one letter. I would need it to search incrementaly (as I type... Sorry I'm a french dude ) so that at the first letter I type, it searches for the nearest match and then for the second letter I type it searches for a new best match and so on...

    what you posted only lets me write one letter and then if I type a second one, it overwrites the first letter.

    any ideas?

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Here's a Post I answered on the Same Question for another Member..

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Thank you guys!!! you are the best!

    Works great now!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Everything works great but I would like to make a Sub ot of the code so that I don't have to rewrite the code for each of my combo boxes.... Would you know why I get a GPF in module "User.exe" when I use this code?

    Public Sub proTrouverDansCombo(ctl As Control, KeyCode As Integer)
    Dim iIndex As Integer
    Dim iStart As Integer
    iStart = ctl.SelStart
    iIndex = SendMessage(ctl.hwnd, CB_FINDSTRING, 0, ByVal ctl.Text)
    If iIndex > -1 And KeyCode <> vbKeyDelete And KeyCode <> vbKeyBack Then
    ctl = ctl.List(iIndex)
    ctl.SelStart = iStart
    ctl.SelLength = Len(ctl)
    End If
    End Sub

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

    I call the Sub this way:

    Private Sub dataClient_Appellatif_KeyUp(KeyCode As Integer, Shift As Integer)
    Call proTrouverDansCombo(Me.ActiveControl, KeyCode)
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width