开发者

Is it possible to change a Winforms combobox to disable typing into it?

开发者 https://www.devze.com 2022-12-22 04:21 出处:网络
So that it just allows selecting items already inside, but not allow typing/editing the t开发者_JS百科ext inside it?Set ComboBox.DropDownStyle to ComboBoxStyle.DropDownList.After trying ShaneFulmer\'s

So that it just allows selecting items already inside, but not allow typing/editing the t开发者_JS百科ext inside it?


Set ComboBox.DropDownStyle to ComboBoxStyle.DropDownList.


After trying ShaneFulmer's answer, I noticed that the style of the drop down was changed. This was a problem for me and apparently there is no good way of changing it. (Background color doesn't actually change it.)

I ended up adding a keypress handler to prevent adding text.

private void myCombo_KeyPress(object sender, KeyPressEventArgs e)
{
    e.Handled = true;
}
0

精彩评论

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