devxlogo

Add ‘Type Ahead’ Functionality to Combo Boxes

Add ‘Type Ahead’ Functionality to Combo Boxes

You can add ‘Type Ahead’ functionality to the standard VB ComboBoxcontrol with this subroutine:

 Sub ComboTypeAhead(Combo As ComboBox)Dim i As Integer, _        KeyString As String, _        KeyLen As IntegerKeyString =3D Combo.TextKeyLen =3D Len(KeyString)gblTypeAhead =3D FalseIf KeyLen > 0 ThenFor i =3D 0 To Combo.ListCount - 1If Left(Combo.List(i), KeyLen) =3D _        KeyString ThenCombo.SetFocusCombo.ListIndex =3D iCombo.SelStart =3D KeyLenCombo.SelLength =3D Len(Combo.Text) _        - KeyLenExit ForEnd IfNext iEnd IfEnd Sub

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

See also  Does It Make Sense to Splurge on a Laptop?
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist