Binding two values to combobox display member property

  • Thread starter Thread starter Hanumanth Reddy
  • Start date Start date
H

Hanumanth Reddy

Any one could help how to bind two table field values
into combobox display member property. I mean i have two
fields in a table. One is states description and another
is states codes.I want to add these two fields to
combobox display property.

Any body knows this solution, post it.
 
You can write your own class that takes the 2 parameters and override
ToString method. In this example, it is useless (I did it with string
because I do not know your data structure), but val1 and val2 may be in an
another type and this time, it would help you to do what you want.

class TableItem {
private string val1;
private string val2;
public TableItem(string val1, string val2) {
this.val1=val1;
this.val2=val2;
}
public override string ToString() {
return val1+" "+val2;
}
}

To add the value in you combobox, do like following :
comboBox1.Items.Add(new TableItem("first","second"));
comboBox1.Items.Add(new TableItem("third","fourth"));
comboBox1.Items.Add(new TableItem("fifth","sixth"));

Hope it helps,

Ludovic Soeur.
 
Hanumanth,

When it is a datatable you are talking about, than you can add an extra
column to that with an expression where in you have connected the other two
columns.

I hope this helps,

Cor
 

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

Back
Top