Find faster a String in Combo or ListBox while typing (Using SendMessage API)
This code is useful to look at a string inside a ComboBox or ListBox, while you typing it
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
Private Sub Combo1_KeyPress(KeyAscii As Integer) Dim CB As Long Dim FindString As String Const CB_ERR = (-1) Const CB_FINDSTRING = &H14C If KeyAscii < 32 Or KeyAscii > 127 Then Exit Sub If Combo1.SelLength = 0 Then FindString = Combo1.Text & Chr$(KeyAscii) Else FindString = Left$(Combo1.Text, Combo1.SelStart) & Chr$(KeyAscii) End If CB = SendMessage(Combo1.hWnd, CB_FINDSTRING, -1, ByVal FindString) If CB <> CB_ERR Then Combo1.ListIndex = CB Combo1.SelStart = Len(FindString) Combo1.SelLength = Len(Combo1.Text) - Combo1.SelStart End If KeyAscii = 0 End Sub
Original Comments (3)
Recovered from Wayback Machine