如何从WPF数据网格只能修改的项目 [英] How to get only modified Items from WPF Data Grid

查看:136
本文介绍了如何从WPF数据网格只能修改的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经绑定列表,可编辑的DataGrid的WPF

I have binded a list with Editable WPF DataGrid

我想只能从WPF数据网格修改为项目选择更新。

I want to get only the modified Items from the WPF Data Grid for updation.

请让我知道如何做到这一点。

Please let me know how to do this.

推荐答案

我有我的WPF的DataGrid的应用程序设置为这样:

I have my WPF datagrid app set up as so:

1)手动定义的所有列,设置其绑定,每一个绑定指定的,它会通知源更新

1) Manually defined all the columns, set their bindings and for each binding specified that it notifies on source updates

2)增加了对DataGrid的SourceUpdated事件的事件处理程序

2) Added an event handler for the datagrid's SourceUpdated event

3)在事件处理我只有以下code:

3) In the event handler I have only the following code:

this.updatedItems.Add(BindingOperations.GetBindingExpression(e.TargetObject, e.Property).DataItem as MyClass); 

updatedItems是HashSet的<>和MyClass的是绑定到DataGrid的ItemsSouce对象的类型

updatedItems is a HashSet<> and MyClass is the type of objects bound to the datagrid's ItemsSouce.

4)当用户点击保存按钮,我只是列举了HashSet的。 HashSet的是好的,因为它只含有唯一值。因此,如果一个行被编辑多次或者即使在同一行中的多个小区进行了编辑,该HashSet的将仍然只包含该对象的单个条目。

4) When the user clicks on the save button I simply enumerate the hashset. Hashset is nice, because it only contains unique values. So if a row is edited multiple times or even if multiple cells in the same row are edited, the hashset will still only contain a single entry for the object.

这篇关于如何从WPF数据网格只能修改的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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