10

How can I make a listbox dropdown like a combobox?

Or is it possible to configure a combobox so that the user can't add values but rather only select from the available list of values?

This is for a desktop application.

Junaith
  • 3,298
  • 24
  • 34
codingguy3000
  • 2,695
  • 15
  • 46
  • 74
  • EDIT: What Nelson said. Also, by default, a user will only be able to select items from a ComboBox. – oltman May 25 '10 at 14:18
  • That's true, both WinForms and WPF have a ComboBox control. – Nelson Rothermel May 25 '10 at 14:21
  • @oltman, the default in WinForms is to allow input of any text as well as selecting from the list. – ChrisF May 25 '10 at 14:22
  • @ChrisF I guess I can only speak to WPF. Thanks for the clarification. – oltman May 25 '10 at 14:35
  • @oltman - I had to double check! It would have helped in the post had been tagged "winforms". – ChrisF May 25 '10 at 14:44
  • Guys I didn't know the difference between winforms and WPF. (I'm a SQL Server developer trying to build out my skill set). But thanks to my stackoverflow friends I know the difference now. Thanks – codingguy3000 May 25 '10 at 15:27
  • +1 for an excellent question leading to a good solution of using ComboBox instead of ListBox by simply setting its `DropDownStyle` property to `DropDownList`. – Not So Sharp Oct 16 '12 at 13:53
  • possible duplicate of [How can I make a ComboBox non-editable in .net?](http://stackoverflow.com/questions/85702/how-can-i-make-a-combobox-non-editable-in-net) – nawfal Dec 29 '13 at 02:17

3 Answers3

19

The ComboBox control has a DropDownStyle property used to set this. Set it to DropDownList.

Mashmagar
  • 2,556
  • 2
  • 29
  • 38
8

Set the DropDownStyle to DropDownList:

Specifies that the list is displayed by clicking the down arrow and that the text portion is not editable. This means that the user cannot enter a new value. Only values already in the list can be selected. The list displays only if AutoCompleteMode is Suggest or SuggestAppend.

like:

DropDownStyle = DropDownList;
tanascius
  • 53,078
  • 22
  • 114
  • 136
4

Set the ComboBox.DropDownStyle property to DropDownList - that should give you the behaviour you need

Kevin McKelvin
  • 3,467
  • 1
  • 27
  • 27