Skip to main content
A newer version of this page is available. .

Binding to Total and Group Summaries

To describe data summaries in a Model or ViewModel, create a corresponding class with summary settings.

public class Summary {
    public SummaryItemType Type { get; set; }
    public string FieldName { get; set; }
}

In the ViewModel, create GroupSummary and TotalSummary collections.

public ObservableCollection<Summary> TotalSummary { get; private set; }
public ObservableCollection<Summary> GroupSummary { get; private set; }

These collections should implement INotifyCollectionChanged so that changes made within the ViewModel are automatically reflected by the Grid Control. The grid’s DataControlBase.TotalSummarySource property should be bound to the ViewModel’s TotalSummary property. The GridControl.GroupSummarySource property should be bound to the ViewModel’s GroupSummary property.

Summary items are generated from templates.

xmlns:dxi="http://schemas.devexpress.com/winfx/2008/xaml/core/internal"

<DataTemplate x:Key="SummaryTemplate"> 
    <ContentControl> 
        <dxg:GridSummaryItem FieldName="{Binding Path=(dxi:DependencyObjectExtensions.DataContext).FieldName, RelativeSource={RelativeSource Self}}" 
                            SummaryType="{Binding Path=(dxi:DependencyObjectExtensions.DataContext).Type, RelativeSource={RelativeSource Self}}"/> 
    </ContentControl> 
</DataTemplate>

A template that describes total summaries should be assigned to the grid’s DataControlBase.TotalSummaryGeneratorTemplate property. A group summary template should be assigned to the GridControl.GroupSummaryGeneratorTemplate property.

<dxg:GridControl Name="grid"
                    ItemsSource="{Binding Source}"
                    ColumnsSource="{Binding Columns}"
                    ColumnGeneratorTemplateSelector="{StaticResource ColumnTemplateSelector}"
                    TotalSummarySource="{Binding TotalSummary}"
                    TotalSummaryGeneratorTemplate="{StaticResource SummaryTemplate}"
                    GroupSummarySource="{Binding GroupSummary}"
                    GroupSummaryGeneratorTemplate="{StaticResource SummaryTemplate}">
    <dxg:GridControl.View>
        <dxg:TableView Name="tableView1"
                        AutoWidth="True"
                        NavigationStyle="Cell"
                        ShowTotalSummary="True"
                        IsTotalSummaryMenuEnabled="False"/>
    </dxg:GridControl.View>
</dxg:GridControl>
See Also