DataGrid databinding Mode=TwoWay

Mar 3, 2009 at 6:12 PM

I'm currently using the WPF toolkit datagrid and binding it to a list<> of objects..

When I insert data in the datagrid (during the execution) the list is correctly updated (execpted the reported Bug?? of having to start with at least one item in the list)

The thing is: when I change the data of an item in the list (in code) the datagrid is not updated (unless I sort a column or something similar)... is there a way to do it.. or is it a reported bug?

Thanks in advance
Mar 3, 2009 at 6:18 PM

DataGrid should get updated in one of the following cases...

  1. Your item object implements INotifyPropertyChanged
  2. The concerned property of your item object is backed by a DependencyProperty.

If none of the above than DataGrid will not get updated automatically.

Mar 3, 2009 at 6:37 PM
Thanks for the reply..

I've seen other posts mentioning the INotifyPropertyChanged.. but I can seem to access it in my class... What is the required namespace?

I would also like to know about the second hipothesis you mentioned.. is there a discusion already on the subject?

Thanks in advance
Mar 4, 2009 at 12:00 PM
It's System.ComponentModel.INotifyPropertyChanged.

As for your other question, a usable workaround is to make your collection class itself a generic with the type of your business object as its type argument.
Mar 4, 2009 at 6:23 PM
Thanks for your input...

:P (I know these are trully rookie questions)....

I'm staring to figure it out... still I believe the datagrid should do that automatically, or recurring to Binding mode... for instance.. like I mentioned earlier.. if I sort the data the itemsource is updated.. even without the INotifyPropertyChanged..

Do you know if this will be fixed in a next version of the datagrid?

thanks in advance
Mar 4, 2009 at 7:02 PM
The DataBinding engine in WPF works on the basis of either INotifyPropertyChanged or DependencyProperty. The conceptual problem is to know when the value of property changed so that other things can be  updated. Normal CLR properties doesnt provide any notification when a property changes. Hence there is no way the DataBinding engine could know about the property value change. Hence no updates in the control either. The reason why it works on sorting is because on such operations entire DataGrid (itemscontrol) gets refreshed, reevaluating the bindings and hence picking up the property changes.
May 4, 2009 at 8:39 PM
I bind an ObservableCollection<T> to the grid. T has a few DependencyPoperty. When I update the object, the grid doesn't refresh the change until I scroll the row out of the view and scroll back. It seems the grid still doesn't know the value being updated.
Is there anything I missed?

May 12, 2009 at 4:38 PM


I'm also trying to make this two way binding, but implementing the INotifyPropertyChanged interface. But the datagrid is still not being update also, as reported by "depend" on the previous post.

I'm binding a derivated class from ObservableCollection<T> to the grid, and T implements the INotifyPropertyChanged as mentioned and also IEditableObject. Debugging I can see that the PropertyChanged event is fired when I change the specific cell, but the datagrid is not updated.

What can be missing? What else could I try?

Thanks in Advance for any suggestions.

May 12, 2009 at 4:43 PM


Please don't waste your time trying to help me on this topice. I just found out my silly mistake.

I was firing the PropertyChanged event BEFORE actually updateing the object value. Now I'm doing something like:









public bool Use
                return _use;

                if (_use != value && this.PropertyChanged != null)
                    _use = value;
                    this.PropertyChanged(this, new PropertyChangedEventArgs("Use"));
                    _use = value;