I have inherited multiple DataTables with differing column names that are all currently being displayed in their own DataGridViews. I'd like to create a new additional DataGridView that will display them all in a single DataGridView. For example (very much simplified):
public class DataTableA: DataTable
{
public DataTableA()
{
this.Columns.Add("DateA", typeof(string));
this.Columns.Add("PriceA", typeof(string));
this.Columns.Add("SomeOtherFieldA", typeof(string));
}
}
public class DataTableB: DataTable
{
public DataTableB()
{
this.Columns.Add("DateB", typeof(string));
this.Columns.Add("PriceB", typeof(string));
this.Columns.Add("SomeOtherFieldB", typeof(string));
}
}
I'd like to display values from DataTableA.DateA and DataTableB.DateB in a single column, and values from DataTableA.PriceA and DataTableB.PriceB in a single column in the new DataGridView. I've been exploring making a common base class or interface but haven't been having much luck yet. Without changing the column names (not an option), is it possible to make a binding that will be able to display both in the same column?
Edit:
Unfortunately I don't think simply merging or aggregating the DataTables into a new DataTable will work because the system was designed so that there is logic inside the DataTableX classes (for example, DataTableA and DataTableB) to handle push data and update the corresponding row in the DataTable.
Also, I'm not trying to merge rows from multiple DataTables into a single row, I'm trying to display mutliple columns with different names in a single column in the DataGridView. For example, say there was data like this:
DataTableA:
DateA PriceA SomeOtherFieldA 20141118 2.0 a 20141119 3.0 b
DataTableB:
DateB PriceB SomeOtherFieldB 20141118 4.0 c 20141119 5.0 d
I'd like to display the following in the DataGridView:
Date Price 20141118 2.0 20141119 3.0 20141118 4.0 20141119 5.0