This example demonstrates how to bind GridControl's selected rows to a property in ViewModel in a MVVM-based application. The SelectionAttachedBehavior helper class used in this sample, provides a bindable SelectedItemsSource property, that can be used to define selection at the ViewModel level.
Note, we made the SelectionAttachedBehavior class as generic as possible, and the same approach can also be used for other controls that support multiple selection. This example demonstrates how this can be done when working with the standard ListBox control, as well as with the standard DataGrid.
Question Comments
Added By: S Sharma at: 12/18/2012 10:27:47 PM
Hi
I am using this procedure to preserve selected rows for the WPF GridControl, but as we are updating the grid with new data in a timer, the selected rows are still getting lost. Please suggest how should we modify this sample so as to preserve grid selected rows even between the updates (like same selected rows should be present after the grid is updated with new data in a separate thread). Also, We are using a NavigationStyle=Cell, so just wanted to also check if we need to change the NavigationStyle to Row for your below sample to work with grid updates?
Thanks
Added By: Vidhyadhar Dhumal at: 3/25/2014 8:27:13 AMIn this example how to avoid multiple selection of rows. Our requirement is user should not be able to select mutiple rows. only single row should be allowed ro select. Hope this clarifies our requirement.
Added By: Michael Ch (DevExpress Support) at: 5/26/2015 7:06:46 AMHello Vidhyadhar Dhumal,
We accidentally discovered that your initial post was outside the scope of our Support Center. Please accept our sincere apologies for not responding in a timely manner.
If this task is still important for you, find a couple of minutes to refer to the Q581629 thread. To implement the required selection mode, use the SelectionMode property as described in the Multiple Row Selection topic. To learn more about selection capabilities of the GridControl, refer to Selection.
The issue with losing the selection during updating the grid was discussed in Q452866, you can find all information there.