【发布时间】:2018-01-27 16:29:25
【问题描述】:
我正在尝试将项目添加到 DataGrid,这与我使用 x.Items.Add(x); 时不同。对于 ListView 它只显示空白行。此 DataGrid 一次仅显示 1 行并且必须是可编辑的,如果您认为有更好的方法而不是 DataGrid,那么我愿意接受建议。我已经确保值的数量与列的数量相匹配,这是一个开始的问题,但似乎我仍然没有更接近解决这个问题。我已经尝试阅读许多类似的问题,但没有一个能够解决我的问题,我哪里出了问题?
rw_container 是我用来将 DataGrid 插入到的空白网格
private void AddGrid<T>(T obj) where T : ICategory
{
data = new DataGrid();
PropertyInfo[] props = typeof(T).GetProperties();
foreach (PropertyInfo x in props)
{
data.Columns.Add(new DataGridTextColumn() { Header = x.Name, Width = 100 });
}
//How to add the rows here?
rw_container.Children.Add(data);
}
【问题讨论】:
-
为什么不使用 MVVM?这要容易得多...stackoverflow.com/questions/13296399/mvvm-datagrid-binding