在已创建的列中添加行到WPF 4.0中的数据网格视图 [英] Adding Rows To data grid View in WPF 4.0 in already created column
本文介绍了在已创建的列中添加行到WPF 4.0中的数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在我创建的数据网格中添加行并添加它的列。
谢谢
How can I add rows in my datagrid that I created and add it's column already.
Thanks
推荐答案
这是你的Xaml:
Hi,
That is your Xaml:
<Window x:Class="WpfApplicationTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<DataGrid ItemsSource="{Binding Path=DataView}"/>
</Grid>
</Window>
这是你的代码:
That is your Code:
public partial class MainWindow : Window
{
private DataTable DataTable { get; set; }
public DataView DataView { get; set; }
public MainWindow()
{
InitializeComponent();
DataTable = new DataTable();
DataTable.Columns.Add("Test");
DataView = DataTable.DefaultView;
DataContext = this;
AddRow();
AddRow();
}
private void AddRow()
{
DataRow dr = DataTable.NewRow();
dr["Test"] = "Wert1";
DataTable.Rows.Add(dr);
}
}
希望这会有所帮助:-D
Hope this helps :-D
<a href=""></a>[<a href="" target="_blank">^</a>]
这篇关于在已创建的列中添加行到WPF 4.0中的数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文