How to make Combobox in winforms readonly
Solution 1:
make DropDownStyle
property to DropDownList
instead of DropDown
then handle the TextChanged
event to prevent user changing text.
Solution 2:
The article ComboBox-with-read-only-behavior suggests an interesting solution:
Create both a readonly textbox and a combobox in the same place. When you want readonly mode, display the textbox, when you want it to be editable, display the combobox.
Solution 3:
Not sure if this is what you're looking for but...
Set the DropDownStyle = DropDownList
Then on the SelectedIndexChanged event
if (ComboBox1.SelectedIndex != 0)
{
ComboBox1.SelectedIndex = 0;
}
This ugly part is that they will "feel" like they can change it. They might think this is an error unless you give them an alert telling them why they can't change the value.
Solution 4:
The best thing I can suggest is to replace the combo-box with a read-only textbox (or just perhaps a label) - that way the user can still select/copy the value, etc.
Of course, another cheeky tactic would be to set the DropDownStyle
to DropDownList
, and just remove all other options - then the user has nothing else to pick ;-p