I've got a ComboBox
on a winforms app with this code:
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems; DataTable t = new DataTable(); t.Columns.Add("ID", typeof(int)); t.Columns.Add("Display", typeof(string)); for (int i = 1; i < 2000; i++) { t.Rows.Add(i, i.ToString("N0")); } comboBox1.DataSource = t; comboBox1.ValueMember = "ID"; comboBox1.DisplayMember = "Display";
I then follow these steps when the window opens:
ComboBox
drop down button -- this displays the list of items and selects the text in the ComboBox
Is this a bug in the ComboBox
? I'm using Windows 7 if that matters. Am I configuring the ComboBox
wrong somehow?
Note also that using the KEYBOARD uses the autocomplete drop down. So up/down arrow keys are using the front window, but the mouse is using the back window.
Add a single line of code to your ComboBox
KeyDown
event and the problem is solved!
private void comboBox_NameAndID_KeyDown(object sender, KeyEventArgs e) { comboBox_NameAndID.DroppedDown = false; }
Source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With