以编程方式添加列&行到WPF Datagrid [英] programmatically add column & rows to WPF Datagrid

查看:254
本文介绍了以编程方式添加列&行到WPF Datagrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆