编程添加列和放大器;行WPF Datagrid的 [英] programatically add column & rows to WPF Datagrid
问题描述
我新的WPF。我只是想知道我们应该怎么加列和行编程到WPF DataGrid中。在路上,我们用来做什么的Windows窗体。创建表格的行和列,并将其绑定到数据网格。
I'm new to WPF. I just want to know how should we add columns and rows programatically 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.
我相信WPF的DataGrid是位不同在ASP.net和Windows窗体(纠正我,如果我错了)。
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. Let me know if you have any ideas.
推荐答案
要编程添加行:
DataGrid.Items.Add(new DataItem());
要编程添加列:
DataGridTextColumn textColumn = new DataGridTextColumn();
textColumn.Header = "First Name";
textColumn.Binding = new Binding("FirstName");
dataGrid.Columns.Add(textColumn);
查看在WPF DataGrid的讨论板以获取更多信息这篇文章。
这篇关于编程添加列和放大器;行WPF Datagrid的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!