Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Binding a dropdown to 2 concatenated fields

Status
Not open for further replies.

MattWoberts

Programmer
Oct 12, 2001
156
GB
Hi,

Can anyone help me:

I have a DataTable that contains a forename and a surname, and I need to bind my windows forms combo box to the forename and surname (i.e. to get the full name). Does anyone know how to do this?

I know in ASP.net I could use something along theb lines of DataBinding.Eval, but how do I do it in a windows forms app?

Thanks!
 

foreach(DataRow dataRow in dataTable.Rows)
{
string name = (dataRow["Name"].ToString() + " " + dataRow["EntityId"].ToString());

comboBox2.Items.Add(name);

}

hope this helps,

Smitty
 
Cheers - I was looking for some way to do it and still use combo.DataBind, but I think your solution is the only way that is going to work for me - ta!
 
Well, you can modify the DataTable. You can add a column that does not exist in the database.

Code:
DataTable.Columns.Add("NewCol");
foreach(DataRow dr in DataTable.rows)
{
     dr["NewCol"].value = dr["First"].ToString() + " " + dr["Last"].ToString()
}

Then bind it to the new column
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top