WPF Data Grid and TreeList – Summaries for Selected Records (v19.2)

WPF Team Blog
04 October 2019

If your end-users are like most, they need to perform specific operations against selected Data Grid / TreeList records. If your app necessitates such functionality, you may need to provide additional information to your end-users to improve the app’s overall user experience. For example, you may wish to display the total number of selected items or calculate a specific total for records selected within the Data Grid / TreeList.

Prior to v19.2, our WPF Data Grid and WPF TreeList required use of Custom Summaries to address this use case. Our newest version addresses this limitation and allows you to compute summaries against selected records with absolute ease. Your users can now select records and immediately obtain summary values within the Data Grid / TreeList summary footer.

To better explain the power of this new features, let’s quickly consider two usage scenarios:

Selected Items: Count

The TreeList below displays a list of employees.

Goal: Calculate the total count of selected employee records.

You can compute the selected record count with the SummaryItemBase.CalculationMode property. In default mode, our Data Grid and TreeList controls calculate summaries against all rows. To calculate a summary against selected rows, set the SummaryItemBase.CalculationMode property to SelectedRows:

<dxg:TreeListControl SelectionMode="Row">
        <dxg:TreeListSummaryItem FieldName="FullName" 
                                 DisplayFormat="Selected Count={0}" 
                                 CalculationMode="SelectedRows" />
        <dxg:TreeListSummaryItem FieldName="FullName" 
                                 DisplayFormat="Total Count={0}" 
                                 Alignment="Right" />
        <dxg:TreeListView x:Name="view" />

Demo: TreeList - Multiple Node Selection

Selected Rows: Sum

The following screenshot contains a list of product orders.

Goal: Calculate the total purchase price of selected products when at least two products are selected (when no product or only a single product is selected, cost summary will not be computed).

If you set the SummaryItemBase.CalculationMode property to Mixed, our WPF Data Grid will calculate summary by selected rows when count exceeds one; otherwise, it calculates summaries against all rows:

<dxg:GridControl x:Name="grid" SelectionMode="Row">
        <dxg:TableView SummaryCalculationMode="Mixed"
                       ShowTotalSummary="True" />
        <dxg:GridSummaryItem FieldName="Total" SummaryType="Sum" />
        <dxg:GridSummaryItem FieldName="Total" SummaryType="Sum" />

The DataViewBase.SummaryCalculationMode property allows you to specify the calculation mode used for all summaries within the grid’s view.

Demo: Data Grid - Web Style Row Selection

Your Thoughts Count

Please let us know what you think about the new feature, or if you have any additional requests related to it.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.