如何在WPF中将数据与DataGrid ItemSource合并 [英] How to merge data with DataGrid ItemSource in WPF

查看:76
本文介绍了如何在WPF中将数据与DataGrid ItemSource合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,其中我有两个表单,一个包含DataGrid for Master,双击,将打开子表单,允许我进行任何更改,问题是当我更新子信息时我必须更新相同的相关关于我的Master DataGrid的信息。



供您参考,我使用的是C#。



我试过以下是反映变化。



 DataTable _MyTable; 

_MyTable.PrimaryKey = new DataColumn [] {_ MyTable.Columns [Id]};
((DataView)dgListing.ItemsSource)。ToTable()。合并(_MyTable);
((DataView)dgListing.ItemsSource)。ToTable()。AcceptChanges();

dgListing.Items.Refresh();





但是上面的代码无论如何也无法帮助我。



_MyTable从数据库中获取更新的记录。

dgListing是我的DataGrid

我已经填写了我的DataGrid如下主表格加载的时间



 dt.PrimaryKey = new DataColumn [] {dt.Columns [Id]}; 
dgListing.ItemsSource = dt.DefaultView;





谢谢和问候,

解决方案

I have one scenario in which i have two forms one contain DataGrid for Master and on double click that will open child form which allow me to make any changes, the issue is when i update the child information i have to update same related information on my Master DataGrid.

For your information, I am using C#.

I have try following to reflect the changes.

DataTable _MyTable;

_MyTable.PrimaryKey = new DataColumn[] { _MyTable.Columns["Id"] };
((DataView)dgListing.ItemsSource).ToTable().Merge(_MyTable);
((DataView)dgListing.ItemsSource).ToTable().AcceptChanges();

dgListing.Items.Refresh();



but above code not help me anyway.

_MyTable fetch the updated record from Database.
dgListing is My DataGrid
I have fill my DataGrid as follows at the time of Master Form Load

dt.PrimaryKey = new DataColumn[] { dt.Columns["Id"] };
dgListing.ItemsSource = dt.DefaultView;



Thanks and Regards,

解决方案

这篇关于如何在WPF中将数据与DataGrid ItemSource合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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