PDA

Click to See Complete Forum and Search --> : ComboBox auto complete word


David Laplante
Nov 15th, 1999, 12:06 AM
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 ?

Serge
Nov 15th, 1999, 01:52 AM
Sure thing:



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
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)

David Laplante
Nov 15th, 1999, 02:33 AM
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?

Aaron Young
Nov 15th, 1999, 03:26 AM
Here's a Post (http://www.vb-world.net/ubb/Forum1/HTML/010330.html) I answered on the Same Question for another Member..

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

David Laplante
Nov 15th, 1999, 06:14 AM
Thank you guys!!! you are the best!

Works great now!

David Laplante
Nov 15th, 1999, 06:30 AM
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