|
1 | | -# How-to-get-the-cell-value-of-specific-row-and-column-in-.NET-MAUI-DataGrid-SfDataGrid |
2 | | -This demo shows how to get the cell value of specific row and column in .NET MAUI DataGrid SfDataGrid |
| 1 | +# How to get the cell value of specific row and column in .NET MAUI DataGrid SfDataGrid |
| 2 | +You can get the cell value of specific row and column in [SfDataGrid](https://www.syncfusion.com/maui-controls/maui-datagrid) by using the **SfDataGrid.GetCellValue** method. You need to pass the underlying data object and the mapping name of the column to find the cell value. |
| 3 | + |
| 4 | + |
| 5 | + ```XML |
| 6 | + <StackLayout> |
| 7 | + <syncfusion:SfDataGrid ItemsSource="{Binding Employees}" |
| 8 | + AutoGenerateColumnsMode="None" |
| 9 | + ColumnWidthMode="Auto" |
| 10 | + DefaultColumnWidth="155"> |
| 11 | + |
| 12 | + <syncfusion:SfDataGrid.Columns> |
| 13 | + <syncfusion:DataGridTextColumn MappingName="EmployeeID" |
| 14 | + HeaderText="Employee ID" /> |
| 15 | + <syncfusion:DataGridTextColumn MappingName="Name" |
| 16 | + HeaderText="Name" /> |
| 17 | + <syncfusion:DataGridTextColumn MappingName="IDNumber" |
| 18 | + HeaderText="ID Number" /> |
| 19 | + </syncfusion:SfDataGrid.Columns> |
| 20 | + |
| 21 | + </syncfusion:SfDataGrid> |
| 22 | + |
| 23 | + <Button Text="Click" |
| 24 | + HorizontalOptions="StartAndExpand" |
| 25 | + WidthRequest="460" |
| 26 | + TextColor="Black"> |
| 27 | + <Button.Behaviors> |
| 28 | + <behaviors:ButtonBehavior /> |
| 29 | + </Button.Behaviors> |
| 30 | + </Button> |
| 31 | +</StackLayout> |
| 32 | + ``` |
| 33 | + |
| 34 | +The below code illustrates how to get the cell value of the specific row and column in a button click. |
| 35 | + |
| 36 | + ```XML |
| 37 | + public class ButtonBehavior : Behavior<Button> |
| 38 | +{ |
| 39 | + protected override void OnAttachedTo(Button button) |
| 40 | + { |
| 41 | + base.OnAttachedTo(button); |
| 42 | + button.Clicked += OnButtonClicked!; |
| 43 | + } |
| 44 | + |
| 45 | + protected override void OnDetachingFrom(Button button) |
| 46 | + { |
| 47 | + base.OnDetachingFrom(button); |
| 48 | + button.Clicked -= OnButtonClicked!; |
| 49 | + } |
| 50 | + |
| 51 | + string? cellValue; |
| 52 | + private void OnButtonClicked(object sender, EventArgs e) |
| 53 | + { |
| 54 | + var button = sender as Button; |
| 55 | + var stackLayout = button!.Parent as StackLayout; |
| 56 | + var dataGrid = stackLayout!.Children[0] as SfDataGrid; |
| 57 | + foreach (var column in dataGrid!.Columns) |
| 58 | + { |
| 59 | + if (column.MappingName == "Name") |
| 60 | + { |
| 61 | + var rowData = dataGrid.GetRecordAtRowIndex(1); |
| 62 | + cellValue = dataGrid.GetCellValue(rowData, column.MappingName) as String; |
| 63 | + break; |
| 64 | + } |
| 65 | + } |
| 66 | + Application.Current!.MainPage!.DisplayAlert("ColumnName", cellValue, "Cancel"); |
| 67 | + } |
| 68 | +} |
| 69 | + ``` |
| 70 | + |
| 71 | + |
| 72 | +  |
| 73 | + |
| 74 | +[View sample in GitHub](https://github.com/SyncfusionExamples/How-to-get-the-cell-value-of-specific-row-and-column-in-.NET-MAUI-DataGrid-SfDataGrid) |
| 75 | + |
| 76 | +Take a moment to explore this [documentation](https://help.syncfusion.com/maui/datagrid/overview), where you can find more information about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this [link](https://www.syncfusion.com/maui-controls/maui-datagrid) to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid). |
| 77 | + |
| 78 | +##### Conclusion |
| 79 | + |
| 80 | +I hope you enjoyed learning about how to get the cell value of specific row and column in .NET MAUI DataGrid (SfDataGrid). |
| 81 | + |
| 82 | +You can refer to our [.NET MAUI DataGrid’s feature tour](https://www.syncfusion.com/maui-controls/maui-datagrid) page to learn about its other groundbreaking feature representations. You can also explore our [.NET MAUI DataGrid Documentation](https://help.syncfusion.com/maui/datagrid/getting-started) to understand how to present and manipulate data. |
| 83 | +For current customers, you can check out our .NET MAUI components on the [License and Downloads](https://www.syncfusion.com/sales/teamlicense) page. If you are new to Syncfusion, you can try our 30-day [free trial](https://www.syncfusion.com/downloads/maui) to explore our .NET MAUI DataGrid and other .NET MAUI components. |
| 84 | + |
| 85 | +If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our [support forums](https://www.syncfusion.com/forums), [Direct-Trac](https://support.syncfusion.com/create) or [feedback portal](https://www.syncfusion.com/feedback/maui?control=sfdatagrid), or the feedback portal. We are always happy to assist you! |
0 commit comments