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.
Unfortunately, activation email could not send to your email. Please try again.

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

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"

             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

             xmlns:syncfusion="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms"

             xmlns:local="clr-namespace:SelectionSample"

             x:Class="SelectionSample.MainPage">

 

  <ContentPage.BindingContext>

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

  </ContentPage.BindingContext>

 

  <ContentPage.Resources>

    <ResourceDictionary>

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

    </ResourceDictionary>

  </ContentPage.Resources>

 

  <syncfusion:SfDataGrid x:Name="dataGrid"

                     ColumnSizer="Star"

                     SelectionMode="Single"

                     ItemsSource="{Binding OrderInfo}">

    <syncfusion:SfDataGrid.Behaviors>

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

                            Converter="{StaticResource gridSelectionChangedEventArgs}" />

    </syncfusion:SfDataGrid.Behaviors>

  </syncfusion:SfDataGrid>

</ContentPage>s

 

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.

 

Screenshot:

 

Sample Link:

How to pass selected row info to a command?

Article ID: Published Date: Last Revised Date: Platform: Control:
7388 01/31/2017 01/31/2017 Xamarin.Forms SfDataGrid
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.