Click to See Complete Forum and Search --> : autocomplete - combobox


batsheva
April 19th, 2001, 01:51 PM
Can someone please tell me how i can go about doing an autocomplete on a combo box ?

Thanks!

TH1
April 19th, 2001, 02:13 PM
go to http://www.planet-source-code.com
there are plenty of examples there

Iouri
April 19th, 2001, 02:39 PM
Declare Function SendMessage Lib ""User32"" Alias _
""SendMessageA"" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

Const CB_ERR = -1
Const CB_FINDSTRING = &H14C


'Add the sub

Sub sMatchEntry(cbo As ComboBox, KeyAscii As Integer)
Dim sBuffer As String
Dim lRetVal As Long

sBuffer = Left(cbo.Text, cbo.SelStart) & Chr(KeyAscii)
lRetVal = SendMessage((cbo.hWnd), CB_FINDSTRING, _
-1, ByVal sBuffer)
If lRetVal <> CB_ERR Then
With cbo
.ListIndex = lRetVal
.Text = .List(lRetVal)
.SelStart = Len(sBuffer)
.SelLength = Len(.Text)
End With
KeyAscii = 0
End If
End Sub

' in the KeyPress Event of the Combobox, add:

Private Sub Combo1_KeyPress(KeyAscii As Integer)
sMatchEntry Combo1, KeyAscii
End Sub"





Iouri Boutchkine
iouri@hotsheet.com