I do not want the user to be able to change the value displayed in the combobox. I have been using Enabled = false
but it grays out the text, so it is not very
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
You can change the forecolor and backcolor to the system colors for an enabled combo box, although this may confuse the users (why have it if they can't change it), it will look better.
Why don't you just use a text box? Text box has a "Read only" property, and since you want your combo box only to display data, I don't see why you would need a combo box.
An alternative is that you just cancel out the input for the "on value changed" event. That way you will be displaying your information no mater what user does ...
enter link description here
Just change the
DropDownStyle
toDropDownList
. Or if you want it completely read only you can setEnabled = 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.
Set DropdownStyle
Property to Simple
Add below code to to KeyPress
event of ComboBox
private void comboBoxName_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
return;
}
Add below code to to KeyDown
event of ComboBox
private void comboBoxName_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
return;
}
Here is the Best solution for the ReadOnly Combo.
private void combo1_KeyPress(object sender, KeyPressEventArgs e) {
e.KeyChar = (char)Keys.None;
}
It will discard the keypress for the Combo. It doesn't have "e.KeyChar" !