Object Data Binding

D

Davie

Lets say i have an array of order objects and I wish for these objects to be
bound to a ComboBox.

public order(string id, string name, int price, string details)

order[] orders = new ...........


I know that i can bind them to a combobox by doing the following:
comboBox1.DataSource=orders;
comboBox1.DisplayMember="name";
comboBox1.ValueMember="id";


How can I set the display member to be the name element of the object and
the ValueMember be the actual object?

Many thanks.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Davie,

It is good idea to provide your solution for the archive in case that
someone in future has the same problem.

Thanks
Stoitcho Goutsev (100) [C# MVP]

Davie said:
Solved this problem thanks.


Davie said:
Lets say i have an array of order objects and I wish for these objects to
be bound to a ComboBox.

public order(string id, string name, int price, string details)

order[] orders = new ...........


I know that i can bind them to a combobox by doing the following:
comboBox1.DataSource=orders;
comboBox1.DisplayMember="name";
comboBox1.ValueMember="id";


How can I set the display member to be the name element of the object and
the ValueMember be the actual object?

Many thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top