Reputation: 11090
I have a combobox with the text 'select'. I want to set it so that the user cannot type over that. Currently they are able to. I cannot see any read only option for this though.
Can any body advise.
Thanks.
Upvotes: 1
Views: 951
Reputation: 8636
This works
private void ComboBox_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
Upvotes: 0
Reputation: 4711
If you want it for all items then
set the ComboBox's DropDownStyle property to DropDownList.
If you want it for the 'Select' item alone then handle KeyDown of ComboBox PS: I've --Select-- as the first item in ComboBox
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
{
if (comboBox1.SelectedIndex == 0)
{
e.SuppressKeyPress = true;
}
}
Upvotes: 1
Reputation: 103437
Set its DropDownStyle
property to ComboBoxStyle.DropDownList
.
Reference: http://msdn.microsoft.com/en-us/library/system.windows.forms.comboboxstyle.aspx
Upvotes: 5