Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
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.
C#
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;
Posted
Updated 1-Mar-10 9:53am
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900