Back to Devexpress

How to: Bind the Grid to Total and Group Summaries

wpf-10124-controls-and-libraries-data-grid-mvvm-enhancements-examples-binding-to-total-and-group-summaries.md

latest3.2 KB
Original Source

How to: Bind the Grid to Total and Group Summaries

  • Jan 09, 2023
  • 3 minutes to read

This topic describes how to define total and group summaries in a View Model and display them in the GridControl.

View Example: How to Bind the GridControl to Total and Group Summaries Specified in a ViewModel

Specify Summaries in the ViewModel

  1. Create a SummaryItemType enumeration that lists summary types you want to display in the GridControl:

  2. Create a class that describes a grid summary:

  3. Specify collections of total and group summaries in the ViewModel:

Create a Summary Template

  1. To specify a summary type (Min, Max, or Count), set the SummaryItemBase.SummaryType property to a SummaryItemType enumeration value. Create an ObjectToObjectConverter to map your SummaryItemType enumeration values to the SummaryItemType enumeration values:

  2. Create a template that generates summaries.

Display ViewModel Summaries in the GridControl

  1. Bind the TotalSummarySource and GroupSummarySource properties to total and group summary collections.
  2. Set the TotalSummaryGeneratorTemplate and GroupSummaryGeneratorTemplate properties to a template that generates summaries.
  3. Set the DataViewBase.TotalSummaryPosition property to Top or Bottom to display the Total Summary Panel.
xaml
<dxg:GridControl ...
                 TotalSummarySource="{Binding TotalSummary}"
                 GroupSummarySource="{Binding GroupSummary}"
                 TotalSummaryGeneratorTemplate="{StaticResource SummaryTemplate}"
                 GroupSummaryGeneratorTemplate="{StaticResource SummaryTemplate}">
    <dxg:GridControl.View>
        <dxg:TableView TotalSummaryPosition="Bottom"/>
    </dxg:GridControl.View>
</dxg:GridControl>

See Also

Total Summary

Group Summary

How to: Bind the Grid to a Collection of Columns

Bind to Collections Specified in the ViewModel