I am using WPF DataGrid for displaying a list of items. I had to modify an item, but the item had no INotifyPropertyChanged event on that property (it was a collection).
So my first idea was:
- Update the list behind ItemsSource
- Set ItemsSource property to null to force unbinding
- Set ItemsSource property to the new collection
- Set the SelectedItem to the new item
- Call ScrollIntoView() on the new item
Well, I got a huge exception at step 5. There must be a simpler solution. And there is.
The DataGrid generates a view of the ItemsSource. All I have to do is call the Items.Refresh() method, and it will rebind to the ItemsSource. Everything will be rebound, all updates will be visible. Selected item kept, visibility kept.