Iterate sfDataGrid rows to find the value of Entry control inside the Cell Template
I need help to Iterate sfDataGrid rows to find the value of Entry control inside the Cell Template, I am using direct approach not the MVVM approach. The Entry control is not data bound and will be entered manually.
Thanks
Kasun
Hi Kasun,
Unfortunately, direct access to the internal properties of the DataGrid is not possible. However, if you could provide more information on the purpose of accessing the entry, we may be able to suggest a solution that meets your needs as soon as possible.
Regards,
Karthik Raja
I just want to list some invoice details such as No, Amount and Paid Amount, where the Paid Amount will be entered manually, Then I need to show the paid total in header which is the total of entered value in each row.
To iterate the entry values that are loaded in each row of the DataGrid, you can refer to the following code snippets:
| <StackLayout> <Button Text="IterateRow" Clicked="Button_Clicked"></Button> <sfDatagrid:SfDataGrid x:Name="dataGrid" HeightRequest="600" ItemsSource="{Binding OrderInfoCollection}" GridLinesVisibility="Both" HeaderGridLinesVisibility="Both" DefaultColumnWidth="160"> <sfDatagrid:SfDataGrid.Columns> <sfDatagrid:DataGridTemplateColumn MappingName="OrderID"> <sfDatagrid:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Entry></Entry> </DataTemplate> </sfDatagrid:DataGridTemplateColumn.CellTemplate> </sfDatagrid:DataGridTemplateColumn> <sfDatagrid:DataGridCheckBoxColumn></sfDatagrid:DataGridCheckBoxColumn> </sfDatagrid:SfDataGrid.Columns> </sfDatagrid:SfDataGrid> </StackLayout>private void Button_Clicked(object sender, EventArgs e) { foreach (DataGridRow dataGridRow in ((this.dataGrid.Children[0] as ScrollView).Content as SfView).Children) { foreach (DataGridCell cell in dataGridRow.Children) { if (cell.DataColumn.DataGridColumn.MappingName != null && cell.DataColumn.DataGridColumn.MappingName.Equals("OrderID")) { var text = (cell.Content as Entry).Text; } } } } |
It is also important to note that the code assumes that the MappingName of the DataGridTemplateColumn is "OrderID". You should adjust this value as necessary to match the name of the column in your own DataGrid. We have also attached the sample for your reference.
Attachment: SfDataGridDemo_98d1323.zip
- 3 Replies
- 2 Participants
-
KF Kasun Fernando
- May 9, 2023 03:46 AM UTC
- May 10, 2023 12:24 PM UTC