We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Two way binding for SelectedItems in SfDataGrid

Thread ID:





142769 Feb 19,2019 08:54 AM UTC Feb 22,2019 11:56 AM UTC WPF 3
Tags: SfDataGrid
James Randle
Asked On February 19, 2019 08:59 AM UTC

I have a ViewModel that has a property, ReactiveList SelectedItems, which I want to bind to the SfDataGrid.SelectedItems property.

It needs to be a two way binding:
  • when a user selects multiple items on the SfDataGrid, my ViewModel should receive notification that the collection of selected items has changed.
  • if I programmatically set ViewModel.SelectedItems, then the SfDataGrid should reflect this selection.
I have tried using the following technique, https://www.syncfusion.com/kb/3070/how-to-bind-the-selecteditems-property-of-sfdatagrid-to-viewmodel-property, but that doesn't work because:
  • The binding is only one way, and badly implemented since it creates a new ObservableCollection each time, rather than updating the existing ObservableCollection. By recreating the ObservableCollection each time, any existing handlers attached to the ViewModel property will no longer work. Also, as noted in the comments below the article, 'The OnSelectedItemsChanged method is called multiple times after the first selection. This effectively renders any usage impractical.'
  • It uses an ObservableCollection, not a ReactiveList.
I also found this solution, but it applies to Xamarin, not WPF, https://www.syncfusion.com/forums/127622/how-to-bind-selected-items-in-sfdatagrid-to-viewmodel.
Also, I am unable to test whether this particular approach works with ReactiveLists, or works in a two way fashion.

How can I achieve this without breaking MVVM?


Arulraj A [Syncfusion]
Replied On February 20, 2019 05:31 PM UTC

Hi James, 

Thanks for using Syncfusion product. 

We are working on the requested requirement and we need one more business day to complete it and we will update you with the details on 21 February 2019. 

We appreciate your patience until then. 

Arulraj A 

Mohanram Anbukkarasu [Syncfusion]
Replied On February 21, 2019 01:20 PM UTC

Hi James, 

Thanks for your patience. 

We have created a simple sample to achieve your requirement by updating the existing ObservableCollection rather than creating new one everytime. Please refer the sample from the following link. 

We are unable to provide this sample with ReactiveList. We are currently work on this. We will update you with further details on February 22, 2019. We appreciate your patience until then. 

Mohanram A. 

Jayaleshwari N [Syncfusion]
Replied On February 22, 2019 11:56 AM UTC

Hi James, 
Thanks for your patience. 
We are little bit unclear in creating the ReactiveList you have used to bind to the SfDataGrid.SelectedItems property. Could you please provide more details about ReactiveList with code example/sample? It will be helpful for us to check on this and provide an appropriate solution to your requirement at earlier. 
Jayaleshwari N 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon