Álvaro García
Álvaro García

Reputation: 19356

Refresh a DataGrid in the MVVM pattern

I have a View with a dataGrid. This datagrid bind a property in the ViewModel that is an ObservableCollection.

I edit some data in the dataGrid, and a field is updated by code, because it depends on some operations. Well, if I check the item in the observable collection, I can see that all the data is correct, but the info in the dataGrid is no refresh.

I want to force the refresh because I know that the observableCollection only raise the change property event when I add o remove items, but not if I edit one of them.

Because I am use Entity Framework 4.1, really the ItemsSource of the dataGrid is the local of the DbSet, so I don't know how to implement the notifyPorpertyChanged in the classes of the model edmx, and I am looking for an alternative, like to force refresh the dataGrid.

Because the property of the ViewModel that I use to bing the ItemsSource of the dataGrid is a reference to the local, I mean that to set the property I do myProperty = myContext.MyTable.Local and that raise the event PropertyChanged that I implement in my ViewModel, I try to do myProperty = myContext.MyTable.Local again to try to raise the event and force the refresh of the dataGrid, but it does not work.

What alternatives do I have?

Upvotes: 1

Views: 5582

Answers (1)

John
John

Reputation: 203

Make sure that you have the Binding Mode set to TwoWay. Implement in the set portion of your property OnPropertyChanged and the rest should take care of itself.

Upvotes: 1

Related Questions