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 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:TreeListControl.TotalSummary>
        <dxg:TreeListSummaryItem FieldName="FullName" 
                                 SummaryType="Count" 
                                 DisplayFormat="Selected Count={0}" 
                                 Alignment="Left" 
                                 CalculationMode="SelectedRows" />
        <dxg:TreeListSummaryItem FieldName="FullName" 
                                 SummaryType="Count" 
                                 DisplayFormat="Total Count={0}" 
                                 Alignment="Right" />
    </dxg:TreeListControl.TotalSummary>
    <dxg:TreeListControl.View>
        <dxg:TreeListView x:Name="view" />
    </dxg:TreeListControl.View>
</dxg:TreeListControl>

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:GridControl.View>
        <dxg:TableView SummaryCalculationMode="Mixed"
                       ShowTotalSummary="True" />
    </dxg:GridControl.View>
    <dxg:GridControl.TotalSummary>
        <dxg:GridSummaryItem FieldName="Total" SummaryType="Sum" />
    </dxg:GridControl.TotalSummary>
    <dxg:GridControl.GroupSummary>
        <dxg:GridSummaryItem FieldName="Total" SummaryType="Sum" />
    </dxg:GridControl.GroupSummary>
</dxg:GridControl>

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.

8 comment(s)
Artem D
Artem D

First of all - thank you, this is another great feature in your already great product.

I was wondering if it is possible to take this one step further and have the summaries shown outside the actual grid/treelist control. In my case i have multiple grids within the application, and ideally i'd show the summaries (count/sum) in the status bar of the application for the selected grid/treelist. 

Artem

4 October, 2019
Gustavo Marzioni
Gustavo Marzioni
+1 for Winforms!
4 October, 2019
Hedi Guizani
Hedi Guizani

Even that this feature can be implemented in winform via custom summary we love to have it as native feature as well as summary expressions like in reports

Thank you for making such great components

6 October, 2019
Cedrus Bank SAL
Cedrus Bank SAL

Great feature.

+1 for Winforms!

6 October, 2019
Michael Ch (DevExpress Support)
Michael Ch (DevExpress Support)

@Artem,

At the moment, I see two possible solutions:

Use the column's TotalSummaryText property to access the summary text displayed within a column and show the formatted summary text as it is beyond the GridControl. Note that this property is a dependency property so it is possible to bind this property to an external control if necessary as follows:

<TextBlock Margin="5" Text="{Binding Path=Columns[Age].TotalSummaryText, ElementName=grid}" />

An example demonstrating this approach in action is available in the Q389597 ticket.

Another solution is to call the GetTotalSummaryValue for a specific summary item and display the returned value as you need.

Should you face any difficulties using these solutions, please feel free to post a ticket to our Support Center at https://www.devexpress.com/ask. We will be happy to assist you.


Thanks,

Michael

7 October, 2019
Artem D
Artem D

Thanks Michael, i'll give it a try after i upgrade to 19.2!

Artem

9 October, 2019
Ralf Heumesser
Ralf Heumesser

For me it doesn't work with my LinqInstantFeedbackSource and            InstantFeedbackSource.AreSourceRowsThreadSafe = true

25 October, 2019
Alex Chuev (DevExpress)
Alex Chuev (DevExpress)

Ralf,

GridControl can only calculate summaries for selected records on the client. Therefore, this feature cannot work with server-side data sources.

28 October, 2019

Please login or register to post comments.