PsuedoTypeahead for Combo/List box using text box
Posted: 2002-06-01
By: ArchiveBot
Viewed: 55
Filed Under:
No attachments for this post
To allow a user to typeahead to a specific item in a list/combo box allowing a little more flexability.
Original Author: James Travis
Inputs
Data entry in text box.
Assumptions
Basically this demonstrate how to loop thru a combo/list box control and compare the typed data to the text value displayed in a the control boxes and select the item. Usefully in large selection lists.
Returns
Position and selects the first matching item.
Side Effects
Depending on if the items are sorted the jumping around and selection may look unusual.
Code
'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
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.