How to bind a column in DataGrid to more than one column in Data source?

350 Views Asked by At

I have:

  • DataTable with three columns: Id, FName, LName.
  • Data Grid with two columns: Id, Full Name. Where Full Name column is combination of FName and LName.

How can the Full Name column of DataGrid can be bound to two Data Source columns (FName and LName) without any string manipulation?

1

There are 1 best solutions below

0
On

You could add a new column to the datatable

e.g.:

        private void DGTest_gridBind()
    {
        DataTable table = new DataTable();
        table.Columns.Add("FName", typeof(string));
        table.Columns.Add("LName", typeof(string));

        table.Columns.Add("FullName", typeof(string), "FName + ' ' + LName");

        table.Rows.Add("Jack", "Miller");
        table.Rows.Add("Sam", "Tucker");

        DGTest.DataSource = table;

}