问题描述
我是WPF的新手。我只想知道我们应该如何将列和行以编程方式添加到WPF中的DataGrid。我们以前在windows窗体中这样做的方式。创建表列和行,并将其绑定到DataGrid。我相信WPF DataGrid与ASP.net和Windows窗体中使用的格式有所不同(如果我错了,请更正)。
我有数量的列和列,我需要在DataGrid中绘制,以便用户可以编辑单元格中的数据。
要以编程方式添加一行:
DataGrid.Items.Add(new DataItem());
要以编程方式添加列:
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header =First Name;
textColumn.Binding = new Binding(FirstName);
dataGrid.Columns.Add(textColumn);
查看在WPF DataGrid讨论板上获取更多信息。
I'm new to WPF. I just want to know how should we add columns and rows programmatically to a DataGrid in WPF. The way we used to do it in windows forms. create table columns and rows, and bind it to DataGrid.
I believe WPF DataGrid is bit different the one used in ASP.net and Windows form (correct me if I am wrong).
I have No. of rows and columns which I need to draw in DataGrid so that user can edit the data in the cells.
To programatically add a row:
DataGrid.Items.Add(new DataItem());
To programatically add a column:
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "First Name";
textColumn.Binding = new Binding("FirstName");
dataGrid.Columns.Add(textColumn);
Check out this post on the WPF DataGrid discussion board for more information.
这篇关于以编程方式添加列&行到WPF Datagrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!