I want to use a Combobox
, with DropDownStyle=Simple
, which changes the list of items when typing some content in the box.
The loading of the items is OK, and I can see them in debugging mode on the Items property, but the dropdown is not shown and seems to be empty.
I also tried to force the display of the dropdown putting
MyComboBox.DroppedDown = True;
Any clue on this behavior?
According to MSDN:
ComboBoxStyle.Simple
is the style that
Specifies that the list is always visible and that the text portion is editable. This means that the user can enter a new value and is not limited to selecting an existing value in the list.
So if the list is always visible then where is it. It is not visible because of the Size
that is set by default. Change the height
like so:
MyComboBox.Size = new System.Drawing.Size(256, 150);
The 150
denotes the height in this case. By default the height was something like 21
which was very less. Increase the height to some appropriate figure and the list should be visible.
Also a very important note: Do set the ComboBoxStyle before you set the size. I do not know why but it seems some invalidation or something is amiss here.
So the following would work:
//Will work
MyComboBox.DropDownStyle = ComboBoxStyle.Simple;
MyComboBox.Size = new System.Drawing.Size(256, 150);
but this will not:
//Will not work
MyComboBox.Size = new System.Drawing.Size(256, 150);
MyComboBox.DropDownStyle = ComboBoxStyle.Simple;
The latter might work with some explicit invalidation calls but i did not verify that.
If you want a drop down to open up when the user clicks on the drop down arrow then you would have to use the other combo box styles. In the Simple
style the drop down arrow would not appear and the list would always be visible as the MSDN definition suggests.