WPF

Introducing Summary Calculation Support for Selected Rows in WPF DataGrid

We are happy to announce that in our Essential Studio 2019 Volume 4 release, we added summary calculation support for selected rows in the WPF DataGrid control. This blog provides a walk-through of how to calculate summaries for selected rows and how to use the available options.

The DataGrid allows users to calculate summaries for:

  • Selected rows.
  • All rows.
  • All rows until rows are selected.

The SummaryCalculationUnit enumeration is used to perform these operations.

To calculate a summary of selected rows in the DataGrid, set the SfDataGrid.SummaryCalculationUnit property to SelectedRows.

In the following example, a summary is calculated for group caption summary rows. This summary calculation support is also applicable for both group and table summary rows.

<syncfusion:SfDataGrid x:Name="sfDataGrid"                
                       AllowFrozenGroupHeaders="True"
                       AutoExpandGroups="True"
                       AutoGenerateColumns="False"
                       ColumnSizer="Auto"
                       SummaryCalculationUnit="SelectedRows"
                       ItemsSource="{Binding YearlySalesDetails}"
                       ShowColumnWhenGrouped="False"
                       SelectionMode="Multiple">

A summary row can also be considered while calculating the summary.

<syncfusion:SfDataGrid.GroupSummaryRows>
    <syncfusion:GridSummaryRow Title="Total Sales in Year for selected products: {YearSales}" CalculationUnit="SelectedRows" ShowSummaryInRow="True">
        <syncfusion:GridSummaryRow.SummaryColumns>
            <syncfusion:GridSummaryColumn Name="YearSales"
                                          Format="'{Sum:c}'"
                                          MappingName="Total"
                                          SummaryType="DoubleAggregate" />
            <syncfusion:GridSummaryColumn Name="ProductCount"
                                          Format="'{Count:d}'"
                                          MappingName="Name"
                                          SummaryType="CountAggregate" />
        </syncfusion:GridSummaryRow.SummaryColumns>
    </syncfusion:GridSummaryRow>
</syncfusion:SfDataGrid.GroupSummaryRows>

Here, let’s use the value for the property SummaryCalculationUnit of DataGrid to calculate a summary of the selected rows; otherwise, the summary for all rows will be calculated.

I hope you now understand this feature and how to calculate summaries for selected rows in the WPF DataGrid. You can download a demo of calculating summaries for selected rows from our GitHub samples. To learn more about the summaries in the Syncfusion DataGrid, please refer to our documentation. You can download our 2019 Volume 4 release to check out all our new features and controls.

If you have any questions or require clarification for this control, please let us know in the comments section. You can also contact us through our support forumDirect-Trac, or feedback portal. We are happy to assist you!

Amal Raj Umapathy Selvam

Amal Raj is a Product Lead at Syncfusion. He is a .NET developer with a degree in Information Technology. His area of expertise is providing solutions for WinForms and WPF applications.