Public class autocomboboxclass autocombobox
Inherits system. Windows. Forms. ComboBox
Code generated by Windows Form Designer # region "code generated by Windows Form Designer"
Public sub new ()
Mybase. New ()
'The call is required by the Windows Form Designer.
Initializecomponent ()
'Add any initialization after initializecomponent () is called.
End sub
'Usercontrol override dispose to clear the component list.
Protected overloads overrides sub dispose () sub dispose (byval disposing as Boolean)
If disposing then
If not (components is nothing) then
Components. Dispose ()
End if
End if
Mybase. Dispose (disposing)
End sub
'Windows forms designer required
Private components as system. componentmodel. icontainer
'Note: The following procedure is required by the Windows Forms designer
'You can use the Windows Form Designer to modify this process.
'Do not use the code editor to modify it.
<System. Diagnostics. debuggerstepthrough ()> private sub initializecomponent ()
'
'Autocombobox
'
Me. Name = "autocombobox"
End sub
# End Region
Private sub autocombobox_keypress () sub autocombobox_keypress (byval sender as object, byval e as system. Windows. Forms. keypresseventargs) handles mybase. keypress
AutoComplete (Me, E)
End sub
Public sub AutoComplete () sub AutoComplete (byref CB as ComboBox, byval e as system. Windows. Forms. keypresseventargs)
Dim strfindstr as string
If E. keychar = CHR (8) then
If CB. selectionstart <= 1 then
CB. Text = ""
Exit sub
End if
If CB. selectionlength = 0 then
Strfindstr = CB. Text. substring (0, CB. Text. Length-1)
Else
Strfindstr = CB. Text. substring (0, CB. selectionstart-1)
End if
Else
If CB. selectionlength = 0 then
Strfindstr = CB. Text & E. keychar
Else
Strfindstr = CB. Text. substring (0, CB. selectionstart) & E. keychar
End if
End if
Dim intidx as integer =-1
Intidx = CB. findstring (strfindstr)
If intidx <>-1 then
CB. selectedtext = ""
CB. selectedindex = intidx
CB. selectionstart = strfindstr. Length
CB. selectionlength = CB. Text. Length
E. Handled = true
End if
End sub
End Class
The ComboBox control can be rewritten to quickly find every item that ComboBox matches.