This example shows how to return the collection of visible rows to the ViewModel. For more details, refer to the KA18591: How to synchronize filtered data between the GridControl and ViewModel KnowledgeBaseArticle.
Question Comments
Added By: Kerry Patrick at: 7/23/2014 8:31:53 AM
Hello.
Thank you so much for this example. One problem I encounter when using this code is when I have a GridColumn which uses a custom binding because it relies on an IValueConverter. For example:
<dxg:GridColumn UnboundType="String" Binding="{Binding ItemizedInstruments, Converter={StaticResource ListHasItemsToYesNoConverter}}" Header="Itemized?" ReadOnly="True" Width="Auto" >
</dxg:GridColumn>
After poking around a little bit in the visible object model, it appears that the list of visible row handles can be obtained in the OnFilterChanged event by querying grid.DataController.FilterHelper.VisibleListSourceRows.ToArray(). You can then loop through the handles and call visibleData.Add(grid.GetRow(handle)) to get the collection of visible objects. Can you tell me if this is also an acceptable way to keep the visible objects in sync between the view model and the GridControl, or are there pitfalls to this approach?
Kindest regards,
Kerry
Added By: Ivan (DevExpress Support) at: 7/24/2014 5:20:08 AM Hi Kerry,I have extracted your question to a separate ticket - T133279. Let's continue our discussion there.Added By: Michael DePouw at: 5/12/2015 9:36:18 AM
Thanks for this solution. FYI this solution only works when the user changes the filter. If the ItemsSource is changed but the filter is not the binding will be incorrect.
To address this I added a call update the bound list when the filter changes or the ItemsSource changes.
grid.FilterChanged += OnFilterChanged;
grid.ItemsSourceChanged += grid_ItemsSourceChanged;
Regards,
Mike D.