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

How to pass selected row's data to a command?

Platform: Xamarin.Forms |
Control: SfDataGrid
Tags: selection

SfDataGrid provides two events for selection: SelectionChanging and SelectionChanged. It provides the added items and the removed items as arguments in it. You can pass the selected row info to a command in the ViewModel by using the Xamarin.Forms.Behaviors.

Refer the below code example in which a custom behavior for passing the selected row information to ViewModel is defined.

<?xml version="1.0" encoding="utf-8" ?>

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"







    <local:ViewModel x:Name="viewModel" />





      <local:CustomConverter x:Key="gridSelectionChangedEventArgs" />




  <syncfusion:SfDataGrid x:Name="dataGrid"



                     ItemsSource="{Binding OrderInfo}">


      <local:CustomBehavior Command="{Binding SelectionCommand}"

                            Converter="{StaticResource gridSelectionChangedEventArgs}" />





The below code illustrates the command and the call back implementation to get the selected row information.



The below code illustrates the behavior class implementation for the SfDataGrid.




Sample Link:

How to pass selected row info to a command?

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

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

Up arrow icon

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