views:

1473

answers:

3

Which event fires when DataGrid's source is updating? I've tried DataContextChanged and SourceUpdated but it never worked out.

Actually I need a simple thing. I want, if there is a new row comes, scroll the GridView's scrollbar down to the bottom to see what it was.

A: 

If you are trying to have the grid refresh when something is added to the database itself, that's not going to happen. I'm more familiar with WinForms than WPF but I'm assuming there is no magical way to keep a grid in sync with the database without writing some background process that continuously checks for database changes.

If you are updating the actual data source of the grid (ex. Collection) then that will update the grid.

Cody C
Yes I have some collection, and it's binded with GridView through ItemsSource.
Ike
A: 

Set NotifyOnTargetUpdated = true for the ItemsSource binding and handle TargetUpdated event. If you've multiple bindings, then look for DataTransferEventArgs Property to find out if the target is ItemsSource or not.

rams
+2  A: 

I had the same problem and I manage it this way

DataGrid myGrid = new DataGrid();
CollectionView myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(myGrid.Items);
((INotifyCollectionChanged)myCollectionView).CollectionChanged += new NotifyCollectionChangedEventHandler(DataGrid_CollectionChanged);

You then need to implement the logic in the event handler DataGrid_CollectionChanged.

Hope this helps. Nidal.

Nidal Valot