Automatically matched ComboBox

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.