Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent manual input into a ComboBox in C#

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.

like image 745
Iakovl Avatar asked Mar 10 '12 17:03

Iakovl


People also ask

How do I disable input on ComboBox?

1. Set the Combobox dropdownstyle property to simple and give it a new height in the size property to stop all items from showing. After doing this the control looks like a textbox.

How do I make my ComboBox non editable?

To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList". The ComboBox is now essentially select-only for the user. You can do this in the Visual Studio designer, or in C# like this: stateComboBox.

How do you make a ComboBox read only?

Just change the DropDownStyle to DropDownList . Or if you want it completely read only you can set Enabled = false , or if you don't like the look of that I sometimes have two controls, one readonly textbox and one combobox and then hide the combo and show the textbox if it should be completely readonly and vice versa.


1 Answers

Just set your combo as a DropDownList:

this.comboBoxType.DropDownStyle = ComboBoxStyle.DropDownList; 
like image 165
Reinaldo Avatar answered Sep 23 '22 07:09

Reinaldo