INotifyPropertyChanged的或数据表INotifyCollectionChanged? [英] INotifyPropertyChanged or INotifyCollectionChanged with DataTable?

查看:268
本文介绍了INotifyPropertyChanged的或数据表INotifyCollectionChanged?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有一些troube与数据表。所以,我需要的是每当我在被绑定的DataTable的DataGrid中更改任何细胞来检测。

Hi i am having some troube with DataTables. So What i need is to detect whenever i change any cell in the DataGrid of the DataTable that is binded.

怎么办呢?随着 INotifyPropertyChanged的 INotifyCollectionChanged

请注意:我试图用 INotifyPropertyChanged的,但只有当我在DataTable中设置一些值检测,永不当我改变在DataGrid中的任意单元格中的任何值,我已经试过单向双向但没有任何反应。

Note: I am trying with INotifyPropertyChanged but it only detects when i set some value in the DataTable, and never when i change any value of any cell in the DataGrid, i already have tried OneWay and TwoWay but nothing happens.

在此先感谢!

推荐答案

数据网格将被绑定到的对象的列表。如果您想在单个对象的属性更改网格更新,比的每个包含的对象的必须实施 INotifyPropertyChanged的接口。

The datagrid would be bound to a list of objects. If you want the grid to update when individual object properties change, than each contained object must implement the INotifyPropertyChanged interface.

INotifyCollectionChanged 是集合应该实现一个接口,并且是用于添加和删除事件的通知。

The INotifyCollectionChanged is an interface that the collection should implement, and are for notifications of addition and removal events.

参看如何实现集合在此页面



这里有一个办法的办法您的问题:


Here's a way to approach your problem:


  • 创建一个公开目前在每个的DataRow 持有的属性的新类。在这个类实现 INotifyPropertyChanged的

  • 而不是一个数据表,使用的ObservableCollection&LT的; T> 或你的新类

  • Create a new class that exposes the properties currently held in each DataRow. On this class implement INotifyPropertyChanged.
  • Instead of a DataTable, use an ObservableCollection<T> or your new class.

<为code>的ObservableCollection 已经实现了 INotifyCollectionChanged ,所以这可以节省你自己实现它的努力。

ObservableCollection already implements INotifyCollectionChanged, so this saves you the effort of implementing it yourself.

这篇关于INotifyPropertyChanged的或数据表INotifyCollectionChanged?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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