Articles in this section
Category / Section

How to get the selected row data in Xamarin.Forms DataGrid?

1 min read

The Xamarin DataGrid provides two selection events; the SelectionChanging and SelectionChanged. Both events have the newly added items and the removed items as arguments.

XAML

The SelectionChanged event is hooked to get the data of the selected row.

<ContentPage.Content>
    <syncfusion:SfDataGrid x:Name ="datagrid"
                    ColumnSizer="Star"
                    AutoGenerateColumns="True"
                    SelectionMode="Single"
                    ItemsSource="{Binding OrdersInfo}"
                    SelectionChanged="Datagrid_SelectionChanged"/>
</ContentPage.Content>

C#

Get the selected row information from the GridSelectionChangedEventArgs.AddedItems List.

private void Datagrid_SelectionChanged(object sender, Syncfusion.SfDataGrid.XForms.GridSelectionChangedEventArgs e)
{
    OrderInfo selectedBatchRecord = (e.AddedItems[0] as OrderInfo);
}

 

Note:

The SfDataGrid.SelectionChanging event is raised while selecting a row at the execution time before the selection is completed. It allows you to cancel the selection action by setting the “Cancel” property in the argument.

View sample in GitHub

how to get the row data of the Xamarin Sfdatagrid  

Take a moment to peruse the documentation, where you can find more information about SfDataGrid with examples.

 

Conclusion

I hope you enjoyed learning about how to get the selected row data in Xamarin.Forms DataGrid (SfDataGrid).

You can refer to our  Xamarin.Forms DataGrid feature tour page to know about its other groundbreaking feature representations. You can also explore our  Xamarin.Forms DataGrid documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied