我想将数据表绑定(bind)到 wpf 中的数据网格。此数据网格在右侧显示列标题、正确的行数,但行为空。
当我调试我的数据表时(使用那个:https://stackoverflow.com/a/18353683/4632606)我有一个正确的数据表:
--- DebugTable() ---
07/08/2014 |
---------------------|-
0,0186 |
0,035 |
---------------------|-
我的数据网格有正确的标题“07/08/2014”和 2 个空行。
这是我的 DataGrid Xaml:
<DataGrid AutoGenerateColumns="true" ItemsSource="{Binding Table}"></DataGrid>
我错过了什么?
更新: 我在输出中看到了:
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')
可能是制作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;
}
最佳答案
问题是字符:“/”
感谢您的帮助。
关于c# - 将 DataTable 绑定(bind)到 DataGrid 显示空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28873056/