开发者

c# combo box winform

I have a combobox with the text 'select'. I want to set it so 开发者_Go百科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


Try setting 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;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜