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

SelectedItems of an SfDataGrid

I have a View which contains an SfDataGrid which is set to allow mulitple row selections.
How do I bind the SelectedItems property of an SfDataGrid to my ViewModel? It doesn't appear in the list when I'm editing the XAML, only SelectedItem appears.

2 Replies

MK Muthukumar Kalyanasundaram Syncfusion Team June 6, 2017 06:58 AM UTC

Hi Zeljko, 

Thank you for contacting Syncfusion support. 

We have analyzed your query. In SfDataGrid.SelectedItems is a collection property, so whenever the SelectedItems collection is changed, the property bound with SelectedItems does not get notified for this change. However, you can achieve this by creating an attached property for SelectedItems. And SfDataGrid’s SelectedItems values are set to the attached property by handling SelectedItems.Collectionchanged event. For your reference, we have attached the KB link. Could you please refer to it. 


Please let us know if you have any query. 

Regards, 
Muthukumar K 



RA Rafael December 6, 2022 01:56 PM UTC

I'm using SfDataGrid version 20.1.0.51 and I can achieve this by simply binding a 'public ObservableCollection<object> SelectedItems' property to the SfDataGrid in XAML.

In ViewModel:
private ObservableCollection<object> _selecionados;
public ObservableCollection<object> Selecionados
{
get { return _selecionados; }
set { SetProperty(ref _selecionados, value); }
}
In XAML:
<syncfusion:SfDataGrid
...
 SelectedItems="{Binding Selecionados}" />

Hope it helps!


Loader.
Up arrow icon