Reputation: 23
I ve just started learning WPF, and trying to set the DataGrid with some dataset. I have the appointments from Outlook, and its week numbers. in lst I have list of the appointments that have properties, one of them is "cwHours" - calendar week hours - float array, indexes of which corresponds to calendar week numbers. And the values inside are working hours. So that's the problem screenshot As seen on the screenshot, my array of cwhours is displayed in the column as Single array, But it should be splitted in columns by its indexes in the right side of project name. How can I put the array into the DataGrid, not in one column but in different ones? Thank you.
List<ProjectModel> lst = reader.olProjectList;
DataTable.ItemsSource = lst;
foreach(var x in lst)
{
float[] arrayofcw = x.cwHours;
for (int i = 0; i < arrayofcw.Length; i++)
{
var col = new DataGridTextColumn();
col.Header = i;
DataTable.Columns.Add(col);
}
}
Upvotes: 1
Views: 176
Reputation: 169150
You should set the Binding
property of the column. You could set the Path
of the Binding
to an index in the array property, e.g.:
var col = new DataGridTextColumn();
col.Binding = new Binding("cwHours[" + i + "]");
col.Header = i;
DataTable.Columns.Add(col);
Upvotes: 1