我想知道我们应该如何以编程方式将列和行添加到 WPF 中的 DataGrid。我们以前在 Windows 窗体中使用的方式。创建表列和行,并将其绑定(bind)到 DataGrid。
我需要在 DataGrid 中绘制行数和列数,以便用户可以编辑单元格中的数据。
最佳答案
以编程方式添加一行:
DataGrid.Items.Add(new DataItem());
以编程方式添加列:
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "First Name";
textColumn.Binding = new Binding("FirstName");
dataGrid.Columns.Add(textColumn);
查看 this post在 WPF DataGrid 讨论板上获取更多信息。
关于c# - 以编程方式将列和行添加到 WPF Datagrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/704724/