The .NET MAUI DataGrid provides various resolving methods to resolve the row index of grid rows based on certain criteria. The actual RowIndex of a row can be resolved by using the ResolveToRowIndex(recordRowIndex) method in SfDataGrid.
The RowIndex of a row can be obtained from DataGridTemplateColumn by retrieving the record index of the row using the bound data from its BindingContext and passing the recordRowIndex to the ResolveToRowIndex() method.
<syncfusion:DataGridTemplateColumn HeaderText="ID Number" MappingName="IDNumber">
<syncfusion:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Text="{Binding IDNumber}" WidthRequest="120" HeightRequest="40" Clicked="Button_Clicked"/>
</DataTemplate>
</syncfusion:DataGridTemplateColumn.CellTemplate>
</syncfusion:DataGridTemplateColumn>
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
var button = sender as Button;
var record = button.BindingContext as Employee;
var recordRowIndex = viewModel.Employees.IndexOf(record);
var rowIndex = datagrid.ResolveToRowIndex(recordRowIndex);
}
}Note : RowIndex of the row can also be accessed by using CellTapped, CellDoubleTapped and CellLongPress events. When using complex layout inside a Template, ensure to set the InputTransparent property of the views loaded in the DataTemplate of the DataGridTemplateColumn as True.
The following screenshot shows how to get the RowIndex of a row when using DataGridTemplateColumn in SfDataGrid.
Take a moment to pursue this documentation, where you can find more about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this link to learn about the essential features of Syncfusion .NET MAUI DataGrid(SfDataGrid).
I hope you enjoyed learning about how to get the RowIndex of a row when using DataGridTemplateColumn in SfDataGrid.
You can refer to our .NET MAUI DataGrid�s feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI 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 .NET MAUI DataGrid and other .NET MAUI components. If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac or feedback portal. We are always happy to assist you!
