ComboBox & AutoComplete

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
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 from the Appended Suggestion. Once I exit the control (or press <enter>) 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
 
What you're asking for doesn't make sense if you think about it properly. Consider this list of items:

ABSRACT
ANACONDA
BANANA
CAMERA

Now, if you have the DropDownStyle set to DropDown and you type "a" then "b" then the text in the control will be "ab" so the autocomplete knows that the only match is "ABSTRACT".

What if the DropDownStyle is set to DropDownList? If you type "a" there would be two matches, but what if you then type "b"? You can't edit the text in the control so there's no "ab" string to use as a base to autocomplete so what should the control do? How would it know whether you wanted matches beginning with "ab" or that you had started typing something new and you wanted matches starting with "b"? It may seem convenient to be able to do what you're asking for but it just isn't possible because you can't have it both ways.
 
Oh I beg to differ. I most certainly can. There are countless program out there that operate exactly in the manner i'm describing. Whether they are DropDownList (No Text Editing) or DropDown (with Text Editing) and both styles do it.

In your example, you suggest that by typing 'a' then 'b' how would the control know that when you typed 'b' you mean ABSTRACT instead of BANANA? Simple: Time.

Many of the times I have seen application controls operate in the manner i'm describing (Windows Explorer is a perfect example) if you type "hello" rapidly, the system of the control will allow you to jump very quickly and smoothly to the first item starting with the string "hello" in the list. but if you type "hel" and then wait a few seconds before typing the second "l" when you do press the second "l" the control will jump to the first item beginning with the letter 'L'.

Play around with the details view of Windows Explorer and test it out.
However, I can pretty much list this question as answered, because what I wanted to know was if this behavior was built in, and by the lack of responses, and your final incredulity, I can gather I'll have to program the key responses myself.

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
 
Back
Top