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.
Set its DropDownStyle
property to ComboBoxStyle.DropDownList
.
Reference: http://msdn.microsoft.com/en-us/library/system.windows.forms.comboboxstyle.aspx
尝试设置DropDownStyle = ComboBoxStyle.DropDownList
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;
}
}
Use DropDownStyle = DropDownList. Hope that helps.
This works
private void ComboBox_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.