I have a large set of data that is generated from a web service in my program. I need to display this data in a DataGrid, but the returned collections of data all have different formats (One may be 3 columns and the next 7) so I cannot create a specific object to hold this data. I am having trouble getting this information to display. Right now I am trying to use this method. I put the data into a two-dimensional list of KeyValuePairs. The Key being the Column this data would belong to, the Value being the output for that row. This is what I am trying right now.
private void SetDataValuesExecute(List<List<KeyValuePair<string,object>>> Data)
{
ResultsCollection = Data;
ValuesDataGrid.Columns.Clear();
foreach (string colName in Data[0].Select(x => x.Key).ToList())
{
DataGridTextColumn tempCol = new DataGridTextColumn();
tempCol.Header = colName;
Binding bind = new Binding();
bind.Source = ResultsCollection.Select(x => x.FirstOrDefault(y => y.Key == colName).Value.ToString()).ToList();
tempCol.Binding = bind;
ValuesDataGrid.Columns.Add(tempCol);
}
}
The ResultsCollection is a non-volatile variable to be used as the source of my bindings. It is a copy of all of the two-dimensional List data I need to construct the DataGrid.
This looks at the first entry an extracts the Column Header values and creates new columns based on that. The binding statement looks at each Row, grabs data for the specified Column, and tries to set that as the Column's Binding. This allows me to have both the column name and a list of all the data that goes in that column. Unfortunately binding the list of data to the column ends up not displaying any data.
So my question is: How do I need to format my data in order for the Column Binding to actually display data? Am I approaching this situation all wrong? Any help is appreciated as I am quite stumped.