INotifyPropertyChanged or INotifyCollectionChanged using a DataTable?

Hi, I have a trick with DataTables. So I need to detect when I change any cell in the DataGrid of the bound DataTable.

How to do it? Using INotifyPropertyChanged or with INotifyCollectionChanged ?

Note. I try to use INotifyPropertyChanged , but it detects when I set some value in the DataTable, and never when I change any value of any cell in the DataGrid, I already tried OneWay and TwoWay but nothing happens.

Thanks in advance!

+3
wpf binding inotifypropertychanged inotifycollectionchanged
source share
2 answers

Dantard will be attached to the list of objects. If you want the grid to be updated when the properties of individual objects change, than each containing object should implement the INotifyPropertyChanged interface.

INotifyCollectionChanged is the interface that the collection should implement, and is designed to notify you of add and delete events.

See the β€œHow to Implement Collections” section on this page .


Here is a way to approach your problem:
  • Create a new class that exposes the properties that are currently stored in each DataRow . In this class, we implement INotifyPropertyChanged .
  • Instead of a DataTable use an ObservableCollection<T> or your new class.

ObservableCollection already implements INotifyCollectionChanged , so this will save you from the effort to implement it.

+9
source share

if you set the items source of your data source to datatable then wpf create an IBindingListView bound to the datagrid.

Now you can edit, add and delete items to your datatable via datagrid. if you want to know when the cell in your datatable changed, you can subscribe to the DataTable.ColumnChanged event.

Why do you want to know when a cell is resized?

-one
source share

All Articles