设置为DropDownList的Combobox DropDownStyle仍然允许文本

编程入门 行业动态 更新时间:2024-10-11 03:15:41
本文介绍了设置为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仍然允许文本

本文发布于:2023-11-06 08:46:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563218.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   文本   Combobox   DropDownList   DropDownStyle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!