
VB6: ComboBox with .Style Dropdown List not maintaining .ListIndex setting
Dear Gurus:
I am looking for work arounds or suggestions for other components to use.
I am using VB6 without any service packs
Normal dropdown list style searching is done only on the first character of
the list values.
I am trying to implement a searchable combobox, that is a combobox that
maintains a search string (upto four chars) across keystrokes.
As the search string grows you move further down the list.
Things seem to work ok except in this situation:
Click on drop down arrow and list appears, start typing and different list
values are highlighted and the textbox portion is updated. Tab out of the
field and the first item with first letter matching last letter typed
replaces that which was highlighted (this appears to be the original default
search method taking over)... not good.
Note: neither _KeyDown nor _KeyUp intercepts the tab key
snippets:
'Assume xyz ComboBox is populated with sorted values
Dim search as String
Private Sub xyz_KeyUp(keycode As Integer, shift As Integer)
Dim c As String, I As Integer
c = UCase(Chr(keycode))
If "A" <= c And c <= "Z" And Len(search) < 4 Then
search = search + c
ElseIf keycode = vbKeyBack And search <> "" Then
search = Mid$(search, 1, Len(search) - 1)
Else
Exit Sub
End If
For I = 0 To xyz.ListCount - 1
If xyz.List(I) >= search Then Exit For
Next I
xyz.ListIndex = I
End Sub
Private Sub xyz_LostFocus()
search = ""
End Sub
Rich DeVenezia