简体   繁体   English

Winforms Combobox - 不允许用户编辑项目

[英]Winforms Combobox - do not allow user to edit items

This is probably something simple. 这可能很简单。 The winforms combobox items by default can be edited by the user, how to disable this? winforms组合框项目默认情况下可以由用户编辑,如何禁用?

设置DropDownStyle = DropDownList。

Set the ComboBox.DropDownStyle to DropDownList . 将ComboBox.DropDownStyle设置为DropDownList

ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList;

Specifies that the list is displayed by clicking the down arrow and that the text portion is not editable. 指定通过单击向下箭头显示列表,并且文本部分不可编辑。 This means that the user cannot enter a new value. 这意味着用户无法输入新值。 Only values already in the list can be selected. 只能选择列表中已有的值。

ComboBox样式设置为ComboBoxStyle.DropDownList

two Method that help you Stop User to not Edit DropDownList: 两个帮助您阻止用户不编辑DropDownList的方法:

A. using Programming code: A.使用编程代码:

DropDownListName.DropDownStyle = ComboBoxStyle.DropDownList;\\ DropDownListName.DropDownStyle = ComboBoxStyle.DropDownList; \\

B. using Design properties of Visual Studio B.使用Visual Studio的设计属性

Set DropDownStyle = DropDownList. 设置DropDownStyle = DropDownList。

I hope this well help you. 我希望这能帮助你。

Try setting the DropDownStyle property to DropDownList. 尝试将DropDownStyle属性设置为DropDownList。 Style of Simple makes it like a listbox, Combobox is what you are seeing allowing editing, and DropDownList only allows user to select. Style of Simple使它像列表框一样,Combobox就是你所看到的允许编辑,而DropDownList只允许用户选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM