Take the 2-minute tour ×

I have a combo Item that I want to populate with a list of objects, similar to "ListItem" Class found in asp.net. Is there a build object for Windows forms that has similar behavior? What I do now is create an utility class that has two properties, ValueField and DisplayField, and then create a generic list from this class and give this list as a datasource to the Combo box, is there a better approach?

PS: We just started using VS 2010


share|improve this question

1 Answer 1

You can simply set your object collection as DataSource of ComboBox. Then set the DisplayMember property of ComboBox equal to Property which you want ComboBox to display.

Similarly for value field you can use ValueMember property of ComboBox

A Utility class only for this purpose would be overkill I guess

share|improve this answer
First Thank you, Second could you please send a simple example? –  odiseh Jan 4 '12 at 6:58
@odiseh: I think my answer is pretty self explanatory. Google for examples. Code will be like this ComboBox combo = new ComboBox(); List<SomeClass> obj = new List<SomeClass>(); combo.DisplayMember = "Some Property"; combo.ValueMember = "Some Property"; combo.DataSource = obj; –  Haris Hasan Jan 4 '12 at 7:07
Thanks Haris, but the problem is that I don't have the SomeClass. In asp.net there is a build in class that makes it easier. What I actual have is a HashTable that is coming from some external library, I need to give this hash table as a source to a combo box, and combo boxes don't accept complex types such as hash tables. So Thats why i need a container class to fill the values, Thanks :) –  user1010572 Jan 4 '12 at 7:16
May be I don't understand you 100%. As far as I know ComboBox accept a Hashtable as datasource. Also you can set HastTable.Value as datasource –  Haris Hasan Jan 4 '12 at 7:24
Setting the hash table as a data source directly gives the error: "Complex DataBinding accepts as a data source either an IList or an IListSource." the hashtable is like this SortedList<object, string> arrDomains ; even when using the Values property it is giving the same thing :S –  user1010572 Jan 4 '12 at 7:33

Your Answer


