设置为DropDownList的Combobox DropDownStyle仍然允许文本 [英] Combobox DropDownStyle set to DropDownList still allows text
本文介绍了设置为DropDownList的Combobox DropDownStyle仍然允许文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
刚学习c#而我偶然发现了一个问题。我有一个Combobox,我想限制List选项。
我已经将DropDownStyle属性设置为DropDownList但它仍然允许用户输入信息在列表之外。我错过了另一个属性还是有其他方法来验证该字段中的条目是否是有效的列表选择?
VS2008 Express
谢谢。
Just learning c# and I've stumbled on a problem. I have a Combobox that I want to limit to the List choices.
I have set the DropDownStyle property to DropDownList but it is still allowing the user to enter information that is outside of the list. Am I missing another property or is there some other way to validate the entry in the field is a valid list choice?
VS2008 Express
Thanks.
this.shiftColourComboBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.paramedicCheckSheetBindingSource, "ShiftColour", true));
this.shiftColourComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.shiftColourComboBox.FormattingEnabled = true;
this.shiftColourComboBox.Items.AddRange(new object[] {
"",
"Green",
"Red",
"Yellow",
"Blue",
"Gold",
"Purple"});
this.shiftColourComboBox.Location = new System.Drawing.Point(98, 87);
this.shiftColourComboBox.Name = "shiftColourComboBox";
this.shiftColourComboBox.Size = new System.Drawing.Size(121, 21);
this.shiftColourComboBox.TabIndex = 23;
推荐答案
请浏览链接:
MSDN:Combobox风格 [ ^ ]
它声明:
指定单击向下箭头显示列表,文本部分不可编辑。这意味着用户无法输入新值。只能选择列表中已有的值。 仅当AutoCompleteMode为Suggest或SuggestAppend 时,才会显示该列表。
Please go through the link:
MSDN: Combobox style[^]
It states:
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. The list displays only if AutoCompleteMode is Suggest or SuggestAppend.
这篇关于设置为DropDownList的Combobox DropDownStyle仍然允许文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文