Articles in this section
Category / Section

How to get the selected row data in .NET MAUI DataGrid (SfDataGrid)?

2 mins read

The .NET MAUI DataGrid provides two key events for handling selection: SelectionChanging and SelectionChanged. These events include arguments for both newly added items and removed items.

XAML

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

<ContentPage.Content>
    <syncfusion:SfDataGrid SelectionMode="Single"
                           ItemsSource="{Binding Employees}"
                           SelectionChanged="Datagrid_SelectionChanged">
    </syncfusion:SfDataGrid>
</ContentPage.Content>
C#

Retrieve the selected row information using the DataGridSelectionChangedEventArgs.AddedItems List.

private void Datagrid_SelectionChanged(object sender, Syncfusion.Maui.DataGrid.DataGridSelectionChangedEventArgs e)
{
  Employee selectedBatchRecord = (e.AddedRows[0] as Employee);
}

> 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.

Download the complete sample from GitHub.

Conclusion

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

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac or feedback portal, or the 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  to leave a comment
Access denied
Access denied