dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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.SetFocus
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.

 

 

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