954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ComboBox & AutoComplete

With a ComboBox there are multiple properties and events that interact.
SelectedIndexChanged()

DropDownStyle
AutoCompleteMode
AutoCOmpleteSource

Now I have a static collection of Objects, that contain String Values as their names. I add those names in alphabetical order (and by way of the list creation numerical indicies as well) to the combobox.

DropDownStyle = DropDownList
In this mode, you cannot "edit" the text of the control, but you can type the 1st character in order to jump through the list. However, it doesn't allow you to type multiple characters to find the 5th item beginning with the letter "B"
Example
BHTY
BOLL
BORI
BTRE
TREE

If I type "B" then "T" it will first jump to BHTY in the list, and then to the TREE item in the list. This is not what I want.

DropDownStyle = DropDown
AutoCompleteMode = Append
AutoCompleteSource = ListItems
THis allows you to type into the text box control, and as what you type matches items currently contained within the list it will implicitly suggest the item closest matching the item you want.
Example
If I type "B" then "T" the text property will reflect "btRE" the "re" being still selected. Once I exit the control (or press ) the event
SelectedIndexChanged() is fired. I want the Index to reflect exactly what is in the Text property as I Type. Thus I Type:
"B" -> BHTY is Selected, and the SelectedIndex = the Index of BHTY in the List Items.
"O" -> BOLL is selected, and the SelectedIndex = the index of BOLL in the List Items.
"R" -> BORI is selected, and the SelectedIndex = the index of BORI in the List Items.

Is there a way to effect this behavior in the default ComboBox with property settings or event handler, or do i have to write my own KeyDown() events in order to jump to the appropriate Item?

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner

JaedenRuiner
Newbie Poster
17 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

The Following code will help you as you have specified in the requirement.

The the code order is changed it will not work properly

so following the order as specified

ComboBox1.AutoCompleteMode = AutoCompleteMode.Append
ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
crazycolour
Newbie Poster
1 post since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

Hi Jaeden

have you found a solution for this?

alex.b
Newbie Poster
1 post since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You