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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Binding SelectedItems doesnt work

Thread ID:





127856 Dec 13,2016 10:51 PM UTC Dec 15,2016 05:24 AM UTC Xamarin.Forms 4
Tags: SfDataGrid
Asked On December 13, 2016 10:51 PM UTC

I am trying to achieve selection with mode multiple and binding SelectedItems in viewmodel as below. But it is not fired or bound. The same way I can achieve single and SelectedItem binding. Is there anything which I am doing wrong or missing here?

Binding between xaml and viewmodel is just fine. I am able to display all items but just doesnt work binding SelectedItems 

In Xaml;

  <sfgrid:SfDataGrid  ScrollingMode="PixelLine"  x:Name="Grid"
                      RowHeight="100" ItemsSource="{Binding Items}"
           SelectedItems="{Binding SelectedItems , Mode=OneWayToSource}"  VerticalOptions="FillAndExpand">        

In ViewModel;

    public ObservableCollection<Item> SelectedItems { get;  }

Ashok N [Syncfusion]
Replied On December 14, 2016 07:38 AM UTC

Hi Emil,    

Thanks for contacting Syncfusion support.   

We have checked your query. In SfDataGrid, it is not possible to bind the SfDataGrid.SelectedItems property to the view model as like SelectedItem property since we can only get the selected items in SfDataGrid. Hence, you will not be able to bind the values in Xaml for SelectedItems property.  
However, you can achieve your requirement by writing behavior for SfDataGrid which will not affect the MVVM pattern. Please refer the below code snippet.  
<sfGrid:SfDataGrid x:Name="dataGrid"  
                   ItemsSource="{Binding OrdersInfo}"  
            <b:EventToCommand Command="{Binding SelectionCommand}"  
                              CommandParameter="{x:Reference Name=dataGrid}"  
                              EventName="SelectionChanged" />  
// In ViewModel.cs  
public ViewModel()  
     selectionCommand = new Command<SfDataGrid>(onSelectionChanged);  
     selectedItems = new ObservableCollection<object>();  
private Command<SfDataGrid> selectionCommand;  
public Command<SfDataGrid> SelectionCommand  
    get { return selectionCommand; }  
    set { selectionCommand = value; }  
private ObservableCollection<object> selectedItems;  
public ObservableCollection<object> SelectedItems  
    get { return selectedItems; }  
    set { selectedItems = value; }  
private void onSelectionChanged(SfDataGrid obj)  
    //you can get the selected items in the datagrid  
    selectedItems = obj.SelectedItems;  
Also, we have prepared a sample for your reference and you can download the same from the below link.  

Replied On December 14, 2016 02:57 PM UTC

Hi Ashok,

thank you this is working but i wish that you consider this as bindable in 2017 releases :) It is misleading. 

Best Regards,


Ashok N [Syncfusion]
Replied On December 15, 2016 05:23 AM UTC

Hi Emil, 

We have checked your query and SelectedItems is Collection and it does not have setter property. So, we do not provide the bindable support  for this. 


Ashok N [Syncfusion]
Replied On December 15, 2016 05:24 AM UTC

Hi Emil, 

We have checked your query and SelectedItems is Collection and it does not have setter property. So, we do not provide the bindable support  for this. 



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