views:

274

answers:

3

How do you prevent user input in a ComboBox to that only one of the items in the defined list can be selected by the user?

A: 

Set the ReadOnly attribute to true.

Or if you want the combobox to appear and display the list of "available" values, you could handle the ValueChanged event and force it back to your immutable value.

Ax
+3  A: 

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.

NYSystemsAnalyst
+1  A: 

Seeing a user banging away at a control that overrides her decisions is a sad sight. Set the control's Enabled property to False. If you don't like that then change its Items property so only one item is selectable.

Hans Passant