How to prevent manual input into a ComboBox in C#

Iakovl picture Iakovl · Mar 10, 2012 · Viewed 93k times · Source

I have a form in C# that uses a ComboBox. How do I prevent a user from manually inputting text in the ComboBox in C#?

this.comboBoxType.Font = new System.Drawing.Font("Arial", 15.75F);
this.comboBoxType.FormattingEnabled = true;
this.comboBoxType.Items.AddRange(new object[] {
            "a",
            "b",
            "c"});
this.comboBoxType.Location = new System.Drawing.Point(742, 364);
this.comboBoxType.Name = "comboBoxType";
this.comboBoxType.Size = new System.Drawing.Size(89, 32);
this.comboBoxType.TabIndex = 57;   

I want A B C to be the only options.

Answer

Reinaldo picture Reinaldo · Mar 10, 2012

Just set your combo as a DropDownList:

this.comboBoxType.DropDownStyle = ComboBoxStyle.DropDownList;