I am using a DataGridControl with the ItemSource bound to a DataGridCollectionViewSource. When I change the DataGridCollectionViewSource.ItemsSource I would like to reselect a specific Row if it still resides in the Grid.
My code looks like this:
// Rerun last query to get changes
ReRunLastQuery();
ipIssueGrid.Items.Refresh();
// Get Grid to rebind
DataGridCollectionView viewSource = (DataGridCollectionView)ipIssueGrid.ItemsSource;
viewSource.Refresh();
ipIssueGrid.Items.Refresh();
// Select Added Issue
foreach (IpIssueQuery ipQuery in ipIssueGrid.Items)
{
if (ipQuery.IpIssue.IpIssueId == ipIssueToAdd.IpIssueId)
{
ipIssueGrid.CurrentItem = ipQuery;
ipIssueGrid.SelectedItem = ipQuery;
break;
}
}
I see that the DataGridCollectionViewSource has seen my OnPropertyChanged() event for the ItemSource and has called my Get Property before I set my CurrentItem and SelectedItem but it looks like the Grid hasn't really rebuilt it's ItemSource and I end up with the 1st row in the grid always selected.
Any suggestions?