I'm writing a GUI in C#, Visual Studio 2008, using the Designer and WinForms. I've got a ComboBox control, and I'd like it to only allow to select from the provided options and not to accept a user-entered string. It doesn't appear to have a ReadOnly property, and disabling it hinders the readability of the control (as well as disallowing user-selection).
You'll need to rebuild the project after you add the ReadOnlyComboProvider class. Then simply drag one of these from the toolbox onto your form and set the properties via a property window or via code. Here's the code example to make the combobox readonly via code: Note: This works similiarly to tooltips...
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.
Set the DropDownStyle property of the combobox to DropDownList . This will allow only items in the list to be selected and will not allow any free-form user input.
Set DropDownStyle to "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