How do I set combobox read-only or user cannot write in a combo box only can select the given items? [duplicate]

白昼怎懂夜的黑 提交于 2019-12-20 09:47:35

问题


I am facing a problem in setting the combo property such that only user can select the values form given items, but I cannot write in the combo box.

How can I do so in C#?


回答1:


Just change the DropDownStyle to DropDownList. Or if you want it completely read only you can set Enabled = 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.




回答2:


I think you want to change the setting called "DropDownStyle" to be "DropDownList".




回答3:


In the keypress event handler:

e.Handled = true;



回答4:


Make the DropDownStyle to DropDownList

stateComboBox.DropDownStyle = ComboBoxStyle.DropDownList;



回答5:


The solution is to change the DropDownStyle property to DropDownList. It will help.




回答6:


Try this:

    private void comboBox1_KeyDown(object sender, KeyEventArgs e)
    {
        // comboBox1 is readonly
        e.SuppressKeyPress = true;
    }


来源:https://stackoverflow.com/questions/3061042/how-do-i-set-combobox-read-only-or-user-cannot-write-in-a-combo-box-only-can-sel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!