Back to Devexpress

TreeListSummaryItem Class

wpf-devexpress-dot-xpf-dot-grid-5f428c12.md

latest13.8 KB
Original Source

TreeListSummaryItem Class

A summary item.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public class TreeListSummaryItem :
    SummaryItemBase
vb
Public Class TreeListSummaryItem
    Inherits SummaryItemBase

The following members return TreeListSummaryItem objects:

Remarks

The DXTreeList allows you to display concise information about individual columns. For instance, you can display the total number of nodes or maximum value, etc. This is called a summary.

The DXTreeList supports the Total Summary type. It stores total summary items within the DevExpress.Xpf.Grid.TreeListControl.TotalSummary collection. Individual summary items are represented by the TreeListSummaryItem objects.

To learn more, see Data Summaries.

Example

The following code sample demonstrates how to display totals. It is shown how to create summary items in code-behind and XAML.

xaml
<Window x:Class="DXTreeList_Totals.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid">
    <Grid>
        <dxg:TreeListControl Name="treeListControl1" AutoGenerateColumns="AddNew">
            <dxg:TreeListControl.View>
                <dxg:TreeListView Name="treeListView1" AutoWidth="True"
                                  KeyFieldName="ID" ParentFieldName="ParentID"
                                  ShowTotalSummary="True"/>
            </dxg:TreeListControl.View>
            <dxg:TreeListControl.TotalSummary>
                <dxg:TreeListSummaryItem FieldName="Name" SummaryType="Count" />
            </dxg:TreeListControl.TotalSummary>
        </dxg:TreeListControl>
    </Grid>
</Window>
csharp
using System.Windows;
using DevExpress.Data;
using DevExpress.Xpf.Grid;

namespace DXTreeList_Totals {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            treeListControl1.ItemsSource = Staff.GetStaff();
            treeListControl1.View.ExpandAllNodes();
            CreateTotal("Age", SummaryItemType.Min);
            CreateTotal("Age", SummaryItemType.Max);
            CreateTotal("Age", SummaryItemType.Average);
        }

        private void CreateTotal(string fieldName, SummaryItemType summaryType) {
            TreeListSummaryItem total = new TreeListSummaryItem() {
                FieldName = fieldName,
                SummaryType = summaryType,
                ShowInColumn = fieldName
            };
            treeListControl1.TotalSummary.Add(total);
        }
    }
}
vb
Imports System.Windows
Imports DevExpress.Data
Imports DevExpress.Xpf.Grid

Namespace DXTreeList_Totals

    Public Partial Class MainWindow
        Inherits System.Windows.Window

        Public Sub New()
            Me.InitializeComponent()
            Me.treeListControl1.ItemsSource = DXTreeList_Totals.Staff.GetStaff()
            Me.treeListControl1.View.ExpandAllNodes()
            Me.CreateTotal("Age", DevExpress.Data.SummaryItemType.Min)
            Me.CreateTotal("Age", DevExpress.Data.SummaryItemType.Max)
            Me.CreateTotal("Age", DevExpress.Data.SummaryItemType.Average)
        End Sub

        Private Sub CreateTotal(ByVal fieldName As String, ByVal summaryType As DevExpress.Data.SummaryItemType)
            Dim total As DevExpress.Xpf.Grid.TreeListSummaryItem = New DevExpress.Xpf.Grid.TreeListSummaryItem() With {.FieldName = fieldName, .SummaryType = summaryType, .ShowInColumn = fieldName}
            Me.treeListControl1.TotalSummary.Add(total)
        End Sub
    End Class
End Namespace
csharp
using System.Collections.Generic;

namespace DXTreeList_Totals {

    public class Employee {
        public int ID { get; set; }
        public int ParentID { get; set; }
        public string Name { get; set; }
        public string Position { get; set; }
        public string Department { get; set; }
        public int Age { get; set; }
    }

    public static class Staff {
        public static List<Employee> GetStaff() {
            List<Employee> employees = new List<Employee>();
            employees.Add(new Employee() { ID = 1, ParentID = 0, Name = "Gregory S. Price", Department = "", Position = "President", Age = 57 });
            employees.Add(new Employee() { ID = 2, ParentID = 1, Name = "Irma R. Marshall", Department = "Marketing", Position = "Vice President", Age = 45 });
            employees.Add(new Employee() { ID = 3, ParentID = 1, Name = "John C. Powell", Department = "Operations", Position = "Vice President", Age = 43 });
            employees.Add(new Employee() { ID = 4, ParentID = 1, Name = "Christian P. Laclair", Department = "Production", Position = "Vice President", Age = 38 });
            employees.Add(new Employee() { ID = 5, ParentID = 1, Name = "Karen J. Kelly", Department = "Finance", Position = "Vice President", Age = 55 });

            employees.Add(new Employee() { ID = 6, ParentID = 2, Name = "Brian C. Cowling", Department = "Marketing", Position = "Manager", Age = 35 });
            employees.Add(new Employee() { ID = 7, ParentID = 2, Name = "Thomas C. Dawson", Department = "Marketing", Position = "Manager", Age = 40 });
            employees.Add(new Employee() { ID = 8, ParentID = 2, Name = "Angel M. Wilson", Department = "Marketing", Position = "Manager", Age = 32 });
            employees.Add(new Employee() { ID = 9, ParentID = 2, Name = "Bryan R. Henderson", Department = "Marketing", Position = "Manager", Age = 28 });

            employees.Add(new Employee() { ID = 10, ParentID = 3, Name = "Harold S. Brandes", Department = "Operations", Position = "Manager", Age = 27 });
            employees.Add(new Employee() { ID = 11, ParentID = 3, Name = "Michael S. Blevins", Department = "Operations", Position = "Manager", Age = 31 });
            employees.Add(new Employee() { ID = 12, ParentID = 3, Name = "Jan K. Sisk", Department = "Operations", Position = "Manager", Age = 44 });
            employees.Add(new Employee() { ID = 13, ParentID = 3, Name = "Sidney L. Holder", Department = "Operations", Position = "Manager", Age = 24 });

            employees.Add(new Employee() { ID = 14, ParentID = 4, Name = "James L. Kelsey", Department = "Production", Position = "Manager", Age = 27 });
            employees.Add(new Employee() { ID = 15, ParentID = 4, Name = "Howard M. Carpenter", Department = "Production", Position = "Manager", Age = 33 });
            employees.Add(new Employee() { ID = 16, ParentID = 4, Name = "Jennifer T. Tapia", Department = "Production", Position = "Manager", Age = 22 });

            employees.Add(new Employee() { ID = 17, ParentID = 5, Name = "Judith P. Underhill", Department = "Finance", Position = "Manager", Age = 41 });
            employees.Add(new Employee() { ID = 18, ParentID = 5, Name = "Russell E. Belton", Department = "Finance", Position = "Manager", Age = 36 });
            return employees;
        }
    }
}
vb
Imports System.Collections.Generic

Namespace DXTreeList_Totals

    Public Class Employee

        Public Property ID As Integer

        Public Property ParentID As Integer

        Public Property Name As String

        Public Property Position As String

        Public Property Department As String

        Public Property Age As Integer
    End Class

    Public Module Staff

        Public Function GetStaff() As List(Of Employee)
            Dim employees As List(Of Employee) = New List(Of Employee)()
            employees.Add(New Employee() With {.ID = 1, .ParentID = 0, .Name = "Gregory S. Price", .Department = "", .Position = "President", .Age = 57})
            employees.Add(New Employee() With {.ID = 2, .ParentID = 1, .Name = "Irma R. Marshall", .Department = "Marketing", .Position = "Vice President", .Age = 45})
            employees.Add(New Employee() With {.ID = 3, .ParentID = 1, .Name = "John C. Powell", .Department = "Operations", .Position = "Vice President", .Age = 43})
            employees.Add(New Employee() With {.ID = 4, .ParentID = 1, .Name = "Christian P. Laclair", .Department = "Production", .Position = "Vice President", .Age = 38})
            employees.Add(New Employee() With {.ID = 5, .ParentID = 1, .Name = "Karen J. Kelly", .Department = "Finance", .Position = "Vice President", .Age = 55})
            employees.Add(New Employee() With {.ID = 6, .ParentID = 2, .Name = "Brian C. Cowling", .Department = "Marketing", .Position = "Manager", .Age = 35})
            employees.Add(New Employee() With {.ID = 7, .ParentID = 2, .Name = "Thomas C. Dawson", .Department = "Marketing", .Position = "Manager", .Age = 40})
            employees.Add(New Employee() With {.ID = 8, .ParentID = 2, .Name = "Angel M. Wilson", .Department = "Marketing", .Position = "Manager", .Age = 32})
            employees.Add(New Employee() With {.ID = 9, .ParentID = 2, .Name = "Bryan R. Henderson", .Department = "Marketing", .Position = "Manager", .Age = 28})
            employees.Add(New Employee() With {.ID = 10, .ParentID = 3, .Name = "Harold S. Brandes", .Department = "Operations", .Position = "Manager", .Age = 27})
            employees.Add(New Employee() With {.ID = 11, .ParentID = 3, .Name = "Michael S. Blevins", .Department = "Operations", .Position = "Manager", .Age = 31})
            employees.Add(New Employee() With {.ID = 12, .ParentID = 3, .Name = "Jan K. Sisk", .Department = "Operations", .Position = "Manager", .Age = 44})
            employees.Add(New Employee() With {.ID = 13, .ParentID = 3, .Name = "Sidney L. Holder", .Department = "Operations", .Position = "Manager", .Age = 24})
            employees.Add(New Employee() With {.ID = 14, .ParentID = 4, .Name = "James L. Kelsey", .Department = "Production", .Position = "Manager", .Age = 27})
            employees.Add(New Employee() With {.ID = 15, .ParentID = 4, .Name = "Howard M. Carpenter", .Department = "Production", .Position = "Manager", .Age = 33})
            employees.Add(New Employee() With {.ID = 16, .ParentID = 4, .Name = "Jennifer T. Tapia", .Department = "Production", .Position = "Manager", .Age = 22})
            employees.Add(New Employee() With {.ID = 17, .ParentID = 5, .Name = "Judith P. Underhill", .Department = "Finance", .Position = "Manager", .Age = 41})
            employees.Add(New Employee() With {.ID = 18, .ParentID = 5, .Name = "Russell E. Belton", .Department = "Finance", .Position = "Manager", .Age = 36})
            Return employees
        End Function
    End Module
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the TreeListSummaryItem class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-tree-list-calculate-custom-node-summaries/CS/CustomNodeSummaries_CodeBehind/MainWindow.xaml#L18

xml
<dxg:TreeListView.NodeSummary>
    <dxg:TreeListSummaryItem FieldName="Statistics" SummaryType="Custom"/>
</dxg:TreeListView.NodeSummary>

wpf-tree-list-display-node-summaries/CS/TreeList_DataBinding/MainWindow.xaml#L25

xml
<dxg:TreeListView.NodeSummary>
    <dxg:TreeListSummaryItem FieldName="Statistics" SummaryType="Average"/>
    <dxg:TreeListSummaryItem FieldName="Name" SummaryType="Count"/>

wpf-tree-list-generate-node-summaries-from-collection/CS/TreeList_DataBinding/MainWindow.xaml#L16

xml
<ContentControl>
    <dxg:TreeListSummaryItem FieldName="{Binding Path=(dxi:DependencyObjectExtensions.DataContext).FieldName, RelativeSource={RelativeSource Self}}"
                SummaryType="{Binding Path=(dxi:DependencyObjectExtensions.DataContext).Type, RelativeSource={RelativeSource Self}}"/>

Inheritance

Object DispatcherObject DependencyObject SummaryItemBase TreeListSummaryItem

See Also

TreeListSummaryItem Members

DevExpress.Xpf.Grid Namespace