views:

3679

answers:

6

Hello,

i am using currently the following code to populate a combobox:

combobox.DataSource = datatable;
combobox.DisplayMember = "Auftragsnummer";
combobox.ValueMember = "ID";

Is there a way to display multiple columns. I tried "Auftragsnummer, Kunde, Beschreibung" for DisplayMember but it did not work.

Thanks,

Dawit

A: 

You can't have a multiple column combo-box.

Would you not be better off using a DataGridView instead

James
The fact that it doesn't exist natively in the .NET framework doesn't mean you can't have it... You can code it yourself, or use a third party control
Thomas Levesque
Think he is looking to do this via the standard controls in .NET tho
James
Thanks James. I will use a DataGridView instead now that am sure that there is no out of the box multiple column combobox in .Net.
da8
You are right James. I was looking for standard controls in .Net.
da8
+1  A: 

It's not available out-of-the-box in .NET (be it Windows forms or asp.net's dropdownlist) CHeck out this code project item for reference on how to build your own. (there are loads more though).

Code Project

Colin
+1 for a good link... and for the google advice ;)
Thomas Levesque
Thanks for you advice but i googled first and i came across those projects too. I decided to ask anyway because it seemed to me that some of the projects are a little bit old and i wanted somehow i definit answer that there is no standard way for implementing multiple columns in a combobox.
da8
They are old, but they should still provide you with the answers on how to create your own "OwnerDrawn" combobox.
Colin
A: 

There's an article on Code Project describing how a Multicolumn ComboBox can be created.

Multicolumn Combobox - Code Project

Pop Catalin
+3  A: 

You can't have multiple columns. Though you can have concatenation of multiple fields as Display Member

Check out: How do I bind a Combo so the displaymember is concat of 2 fields of source datatable?

Rashmi Pandit
A: 

Quick solution
Datatables should be partical classes as far as I remember

  1. Create a 2nd file for your datatable MyDataTable.custom.cs
  2. Add a string property in the partial datatable class called "DisplayProperty"
  3. In that property return a string.format("{0} {1} {2}", Auftragsnummer, Kunde, Beschreibung);
  4. Bind your Datamember to your DisplayProperty
Peter Gfader
Calculated column is even better if you can change the datatable layout
Peter Gfader
A: 

How to get data from two fields in ValueMember ?

Jignesh Patel