Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 8, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Add 'Type Ahead' Functionality to Combo Boxes

You can add 'Type Ahead' functionality to the standard VB ComboBox control with this subroutine:

Sub ComboTypeAhead(Combo As ComboBox)
Dim i As Integer, _
        KeyString As String, _
        KeyLen As Integer

KeyString =3D Combo.Text
KeyLen =3D Len(KeyString)
gblTypeAhead =3D False
If KeyLen > 0 Then
For i =3D 0 To Combo.ListCount - 1
If Left(Combo.List(i), KeyLen) =3D _
        KeyString Then
Combo.ListIndex =3D i
Combo.SelStart =3D KeyLen
Combo.SelLength =3D Len(Combo.Text) _
        - KeyLen
Exit For
End If
Next i
End If
End Sub

Call this routine from the Change event of the ComboBox with the name of the ComboBox as the only parameter. Additionally, you may want to add some code to the KeyPress event to handle the Delete and Backspace keys (that is where the gblTypeAhead variable is used), but other than that, this routine will handle all of the type-ahead functionality.

Jon Rauschenberger
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date