How do I make a combobox stay open after an item is selected in C#?
I want to do this because it is actually a comboBox with a checklist so I can select several items.
Just change the DropDownStyle to DropDownList . Or if you want it completely read only you can set Enabled = false , or if you don't like the look of that I sometimes have two controls, one readonly textbox and one combobox and then hide the combo and show the textbox if it should be completely readonly and vice versa.
It records the currently selected item when the dropdown is opened, and then fires SelectionChanged event if the same index is still selected when the dropdown is closed. It may need to be modified for it to work with Keyboard selection.
The ComboBox class searches for the specified object by using the IndexOf method.
We can disable the combobox by passing the state as “readonly”.
Use ListBox instead, since ComboBox
does that behavior by its core design.
ListBox
gives a similar effect (hence it is still open) and enabling for multi-selection.
If you still want to allow the user to write an option of his own you can still use a DropBox, just set the DropDownStyle property to simple. You'll get something similar with a ListBox but with an TextBox on the top where the user can write somwthing.
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