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 ?
Printable View
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 ?
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
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?
Here's a Post I answered on the Same Question for another Member..
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Thank you guys!!! you are the best!
Works great now!
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