Advertisement
2002VB Miscellaneous #19267

PsuedoTypeahead for Combo/List box using text box

To allow a user to typeahead to a specific item in a list/combo box allowing a little more flexability.

AI

Resumen de IA: 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.

Código fuente
original-source
'You will need 3 controls
'TextBox = Text1
'ComboBox = Combo1
'ListBox = List1
'Then you can cut and paste.
Private Sub Form_Load()
 'Load our test items.
 Combo1.AddItem "Adam"
 Combo1.AddItem "Bill"
 Combo1.AddItem "Dave"
 Combo1.AddItem "Dick"
 Combo1.AddItem "Neville"
 Combo1.AddItem "Norman"
 Combo1.AddItem "Simon"
 Combo1.AddItem "Steve"
 Combo1.AddItem "Stevie"
 Combo1.AddItem "Tom"
 
 List1.AddItem "Adam"
 List1.AddItem "Bill"
 List1.AddItem "Dave"
 List1.AddItem "Dick"
 List1.AddItem "Neville"
 List1.AddItem "Norman"
 List1.AddItem "Simon"
 List1.AddItem "Steve"
 List1.AddItem "Stevie"
 List1.AddItem "Tom"
End Sub
Private Sub Text1_Change()
 Dim cmbInd As Long, lstInd As Long
 
 '0 is the last item in the list not the first
 For cmbInd = (Combo1.ListCount - 1) To 0 Step -1
 If UCase(Left(Combo1.List(cmbInd), Len(Text1.Text))) = UCase(Text1.Text) Then Combo1.ListIndex = cmbInd 'Find and set the selected combo item
 Next
 
 For lstInd = (List1.ListCount - 1) To 0 Step -1
 If UCase(Left(List1.List(lstInd), Len(Text1.Text))) = UCase(Text1.Text) Then List1.Selected(lstInd) = True 'Find and set the selected list item
 Next
End Sub
Comentarios originales (3)
Recuperado de Wayback Machine