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



3 Replies

KK Karthikraja Kalaimani Syncfusion Team May 9, 2023 07:14 AM UTC

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



KF Kasun Fernando May 9, 2023 10:42 AM UTC

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.



KK Karthikraja Kalaimani Syncfusion Team May 10, 2023 12:24 PM UTC

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

Loader.
Up arrow icon