Winforms ComboBox does not expand when clicked, any ideas?
A ComboBox within a Form (modal dialog) does not op开发者_如何学Cen when clicked, however an item can be selected by using the up/down arrow keys. After clicking on another window and the back on the dialog, the ComboBox works as expected, i.e. expands on click.
Weird... any ideas what could be causing this behavior?
Thanks a lot in advance, Peter
EDIT: The Combobox is created by compile time, but populated by runtime.
Invalidating Combobox and enclosing Form did not help.
Following Henk's suggestion, I tried adding a new Combobox using the designer, which results in exactly the same code the existing Combobox has. The new Combobox works fine when empty, but adopts the strange behavior as soon as set the datasource programmatically... Here's what I am doing:
comboBox1.DataSource = langs;
comboBox1.DisplayMember = "NativeName";
comboBox1.ValueMember = "Name";
(langs
is a List<CultureInfo>
with two entries)
Hmmmm. If I preset the Items property with any two items (e.g. "A", "B"), everything works fine..... Huh? This works for me, but seems odd. Is this a bug?
(No, not really, misconception on my side)
Perhaps some event like the OnClick is implemented which sets e.handled to true?
Also, how do you insert the combobox, runtime or compile time? If runtime, perhaps you missed something?
Changing the Combobox' TabIndex from 1 to 3 did the trick. Don't ask me why... :-/
Have you tried dragging the drop down area of your combo box in the designer?
I experienced this exact problem. I had mistakenly set all of the options to style="display:none". This wasn't obvious because the selected option still displays within the combobox, and I was able to navigate the combobox options using my arrow keys, but just like peter described, clicking the drop-down arrow had no effect. After I removed display:none from the options it worked normally.
精彩评论