We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

how to get GridSummaryColumn Value Programatically?

Does anyone know how to get GridSummaryColumn Value Programmatically?


1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team January 30, 2023 02:32 PM UTC

Hi Mariusz Juszkiewicz,

To programmatically retrieve the GridSummaryColumn value in SfDataGrid, use the GetSummaryDisplayTextForRow and GetSummaryDisplayText methods in SummaryCreator.

SfDataGrid allows you, to retrieve the value of summary rows by using the SummaryCreator.GetSummaryDisplayTextForRow method when GridSummaryRow.ShowSummaryInRow is true. Refer to the below code snippet,

private void btnTableSummaryRowClicked(object sender, RoutedEventArgs e)

{

     if (sfDataGrid.View != null && sfDataGrid.View.Records != null && sfDataGrid.View.Records.TableSummaries.Count > 0)

     {

             var summary = this.sfDataGrid.View.Records.TableSummaries[0];

 

             //SfDataGrid allows you, to retrieve the value of summary rows by using the SummaryCreator.GetSummaryDisplayTextForRow method

             //when GridSummaryRow.ShowSummaryInRow is true.               

             var value = SummaryCreator.GetSummaryDisplayTextForRow(summary, this.sfDataGrid.View);

             MessageBox.Show(value);

        

     }

}


And you can also retrieve the value of each summary column by using the SummaryCreator.GetSummaryDisplayText method when GridSummaryRow.ShowSummaryInRow is false. Refer to the below code snippet,


private void btnTableSummaryRowClicked(object sender, RoutedEventArgs e)

{

     if (sfDataGrid.View != null && sfDataGrid.View.Records != null && sfDataGrid.View.Records.TableSummaries.Count > 0)

     {

             var summary = this.sfDataGrid.View.Records.TableSummaries[0];

 

             //Retrieves the summary row value of the UnitPrice and CustomerName column.

             //SfDataGrid allows you, to retrieve the value of summary rows by using the SummaryCreator.GetSummaryDisplayText method

             //when GridSummaryRow.ShowSummaryInRow is false.

             var valueOfUnitPrice = SummaryCreator.GetSummaryDisplayText(summary, "UnitPrice", this.sfDataGrid.View);

             var valueOfCustomerName = SummaryCreator.GetSummaryDisplayText(summary, "CustomerName", this.sfDataGrid.View);

             MessageBox.Show("UnitPrice Summary Column Value: " + valueOfUnitPrice + "\nCustomerName Summary Column Value: " + valueOfCustomerName);

 

     }

}


UG Link: https://help.syncfusion.com/wpf/datagrid/summaries

Find the sample in the attachment.


Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: Sample_e2cd95b4.zip

Marked as answer
Loader.
Up arrow icon