I want to bind a datatable to a datagrid in wpf. This datagrid shows columns header right, the right number of rows, but rows are empty.
When i debug my datatable (with that : https://stackoverflow.com/a/18353683/4632606) i have a correct datatable:
--- DebugTable() ---
07/08/2014 |
---------------------|-
0,0186 |
0,035 |
---------------------|-
And my datagrid have the correct header "07/08/2014" and 2 empty rows.
Here is my DataGrid Xaml:
<DataGrid AutoGenerateColumns="true" ItemsSource="{Binding Table}"></DataGrid>
What i'm missing?
UPDATE: I saw that in output :
System.Windows.Data Error: 40 : BindingExpression path error: '07' property not found on 'object' ''DataRowView' (HashCode=32322646)'. BindingExpression:Path=07/08/2014; DataItem='DataRowView' (HashCode=32322646); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
Maybe an error while making the DataTable?
public DataTable Table { get { return this.GetTable(); } }
private DataTable GetTable()
{
DataTable table = new DataTable();
foreach (var controle in Controles)
{
table.Columns.Add(new DataColumn(controle.Date.ToShortDateString()));
}
DataRow rowMoyenne = table.NewRow();
DataRow rowEtendue = table.NewRow();
for (int i = 0; i < table.Columns.Count; i++)
{
DataColumn column = table.Columns[i];
rowMoyenne[column] = Controles[i].Moyenne.ToString();
rowEtendue[column] = Controles[i].Etendue.ToString();
}
table.Rows.Add(rowMoyenne);
table.Rows.Add(rowEtendue);
return table;
}