How to get the column name on tapping a row in Xamarin.Forms DataGrid?
You can get the column name while tapping a row by using the SfDataGrid.GridTapped event. It provides the row column index in its argument. Thus, using the ColumnIndex you can get the column name of the tapped cell in SfDataGrid.
Refer the below code example in which the GridTapped event is hooked in SfDataGrid.
<ContentPage.Content> <syncfusion:SfDataGrid x:Name ="dataGrid" AutoGenerateColumns="True" ColumnSizer="Star" ItemsSource="{Binding OrdersInfo}" GridTapped="DataGrid_GridTapped"/> </ContentPage.Content>
The below code illustrates how to get the Column name of the tapped cell using the ColumnIndex obtained from the GridTapped event arguments and show it in a DisplayAlert.
private int columnIndex; private string columnName; private void DataGrid_GridTapped (object sender, GridTappedEventsArgs e) { columnIndex = dataGrid.ResolveToGridVisibleColumnIndex(e.RowColumnindex.ColumnIndex); columnName = this.dataGrid.Columns[columnIndex].MappingName; DisplayAlert("Setected Column Name", columnName, "Cancel"); }
On executing the above code and tapping a cell in SfDataGrid, a DisplayAlert will be display the column Name as shown below.
Sample Link:
How to get the column name of the selected row?
Conclusion
I hope you enjoyed learning about how to get the column name on tapping a row in Xamarin.Forms DataGrid.
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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!