For all of you who are searching for auto complete functionality in
..net combobox. I wrote this code yesterday after being unable to find
something usable and workable on the internet. All examples that I've
tried either bulky and simply not elegant and inefficient or does not
work properly. Maybe I was just not lucky and patient enough to try
more examples :) instead I wrote my own code. Hope it helps someone. I
appreciate all comments and bugs in the following code being posted
back to the group.
Regards,
Michael Shapiro
P.S. call this sub from KeyUp event of the combobox
Public Sub AutoComplete(ByVal cbo As
System.Windows.Forms.ComboBox, ByVal e As
System.Windows.Forms.KeyEventArgs)
Dim index As Integer
Dim p As Integer
Select Case e.KeyCode
Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Down,
Keys.Delete, Keys.Tab
Return
End Select
p = cbo.SelectionStart
index = cbo.FindString(cbo.Text.Substring(0, p))
If index = -1 Then Return
cbo.SelectedIndex = index
cbo.SelectionStart = p
cbo.SelectionLength = cbo.Text.Length
End Sub