I think I know what the problem is, but I have no clue as to the solution to it.
I have an observable collection which i populate in a WPF DataGrid.
I have then implemented Drag and Drop for rows in the DataGrid to child grids.
If a row is dragged to another grid I change a value in the ObservableCollection and then display
the underlying data like this:
var q = from standard in DispatchResult
where DispatchResult.Route == RouteName
select standard;
dgRoutedData.ItemsSource = q;
I guess that me setting the itemssource to the result of the above LINQ query breaks the whole auto notification from the observable collection, so how do I get the datagrids to show filtered views that will actually update when items have their “Route” value changed?
You need to notify that the change has occurred – you can always try wrapping the result of the linq query in a new
ObservableCollectione.g.
(this has the disadvantage that you need to operate on the new observable as the previous observable wont raise item changed events for the new observable)
Or just clearing/and re-adding to the existing collection.
I assume though you’ve avoided this because the original collection contains items that you want to filter ‘back-in’ after you’ve removed the filter. In this case you might want to keep a private backing field to hold the actual data, and use
ObservableCollection<T>as a filtered window onto that backing field.e.g.
Or dont re-invent the wheel and use
PagedCollectionViewas someone suggested which wraps the above functionality (a private backing field with a filter predicate and other functionality baked in)