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.
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.
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.
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.
Just set your combo as a DropDownList:
this.comboBoxType.DropDownStyle = ComboBoxStyle.DropDownList;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With