autocomplete AND dropdownlist combobox
I want to give the user the functionality of the autocomplete, allowing them to enter one or more letters and receive a list of possible entries, whilst also ensuring that the user can only select an item from the list and not type any old thing. I know that I cannot use the dropdownlist list option along with autocomplete, but how can I make sure that the user does not enter invalid data?
Basically, at all times during the edit process, I want the data in the combo to be valid, so if a user enters invalid data, maybe the previously selected entry should be selected? Whatever works best.
I want to have the functionality of both autocomplete and dropdownlist.
[670 byte] By [
Zaph0d] at [2008-2-4]
We do support AutoComplete with a DropDownList - although it works more like auto-match. You don't see the auto-complete dropdown but typing characters into the combobox will auto-match the combobox entries. You can get the ComboBox list to auto-popup with the following code in a KeyPress event (or you can sub-class to get this as well).
| |
private void comboBox1_KeyPress(object sender, KeyPressEventArgs e) { ComboBox cb = sender as ComboBox; if (!e.Handled && !cb.DroppedDown && (e.KeyChar != (char)Keys.Return) && (e.KeyChar != (char)Keys.Escape)) { if ((cb.DropDownStyle == ComboBoxStyle.DropDownList) && ((cb.AutoCompleteMode == AutoCompleteMode.Suggest) || (cb.AutoCompleteMode == AutoCompleteMode.SuggestAppend))) { cb.DroppedDown = true; } } }
|
Note - we are looking into making the ComboBox auto popup when using a DropDownList with AutoCompleteMode of either Suggest or SuggestAppend.
Joe
It's new in VS 2005 but is in both Beta 1 and Beta 2.
Joe Stegman
The Windows Forms Team
Microsoft Corp.
This posting is provided "AS IS" with no warranties, and confers no rights.
How would I do this same thing in VB.net?
The dropdownlist on my webform does not have a keypress event.
Currently I can type the first letter of the item and it goes to the first letter of the item in the dropdownlist; however, I have 10,000 so I could like the dropdown list to autocomplete to at least the first 3 letters to get me a bit closer to my desired selection.
Any tips would be great!!!!
Thanks