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]
# 1

You could create a derived version of the ComboBox and override the OnValidating method, like this:


protected override void OnValidating(CancelEventArgs e)
{
int index = FindStringExact(Text);

if (index == -1)
{
e.Cancel = true;
DroppedDown = true;
}


base.OnValidating(e);
}


DavidM.Kean at 2007-9-7 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2

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

JoeStegman at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3

I haven't seen an autocompletemode in the properties. Or is that in beta2?

Kaleb at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 4

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.

JoeStegman at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 5

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

BekDeveloper at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 6

Hi,

Did you manage to get any proper solution for forcing the combo box to select an item from the list while still using autocomplete functionality and dropdown (not dropdownlist) ?

rohangopal at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 7
Joe Stegman wrote:

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

I am using .NET 1.1 and not able to get this thing. Can you please tell me how to do this in .NET 1.1 please with filtering like the Microsoft Internet Explorer

s26f84 at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...