views:

3625

answers:

4

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).

+9  A: 

Set DropDownStyle to "DropDownList"

Phillip Wells
+1  A: 

Try using a DropDownListbox

Mauro
+3  A: 

Set the ComboBox.DropDownStyle property to ComboBoxStyle.DropDownList.

OregonGhost
A: 

Use code similar to the following to set the allowed options and only those options.

comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; comboBox1.Items.AddRange(new object[] { "One", "Two", "Three", "Four"});

David Max