Back to Devexpress

PivotGridGroupCollection Class

wpf-devexpress-dot-xpf-dot-pivotgrid-3bcdc656.md

latest6.5 KB
Original Source

PivotGridGroupCollection Class

Represents a collection of field groups.

Namespace : DevExpress.Xpf.PivotGrid

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

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
public class PivotGridGroupCollection :
    PivotChildCollection<PivotGridGroup>,
    ILockable
vb
Public Class PivotGridGroupCollection
    Inherits PivotChildCollection(Of PivotGridGroup)
    Implements ILockable

The following members return PivotGridGroupCollection objects:

Remarks

The DXPivotGrid provides the capability to arrange fields into groups. Fields which are grouped cannot be separated by end-users by dragging one of them to a different area. Field groups are represented by PivotGridGroup objects, and these are stored within the PivotGridControl.Groups collection.

To learn more, see Field Groups.

Example

The following example demonstrates how to combine fields into a group.

In this example, two fields (“Country” and “Customer”) are combined into a new group at design time, and another two fields (“Category” and “Product”) are combined into a new group at runtime, in this order. This ensures that the “Country” field is followed by “Customer”, and the the “Category” field is followed by “Product”. If you drag the “Region” field and drop it to another area, the “Customer” field accompanies it. This behavior is also true for the second group.

csharp
using System.Windows;
using DevExpress.Xpf.PivotGrid;
using HowToBindToMDB.DataSet1TableAdapters;
using static HowToBindToMDB.DataSet1;

namespace HowToBindToMDB {
    public partial class MainWindow : Window {
        SalesPersonDataTable salesPersonDataTable = 
            new SalesPersonDataTable();
        SalesPersonTableAdapter salesPersonDataAdapter = new SalesPersonTableAdapter();
        public MainWindow() {
            InitializeComponent();
            pivotGridControl1.DataSource = salesPersonDataTable;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e) {
            salesPersonDataAdapter.Fill(salesPersonDataTable);

            // Create a group at run-time
            PivotGridGroup group = pivotGridControl1.Groups.Add(fieldCategoryName, fieldProductName);
        }
    }
}
xaml
<Window x:Class="HowToBindToMDB.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Grid>
        <dxpg:PivotGridControl Name="pivotGridControl1">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldCountry" FieldName="Country" Area="RowArea" 
                                     Group="{Binding ElementName=groupCountryCustomer}" />
                <dxpg:PivotGridField Name="fieldCustomer" FieldName="Sales Person" Area="RowArea" 
                                     Group="{Binding ElementName=groupCountryCustomer}" 
                                     Caption="Customer"/>
                <dxpg:PivotGridField Name="fieldYear" FieldName="OrderDate" Area="FilterArea"
                                     Caption="Year" GroupInterval="DateYear" />
                <dxpg:PivotGridField Name="fieldCategoryName" FieldName="CategoryName"
                                     Area="ColumnArea" Caption="Category" />
                <dxpg:PivotGridField Name="fieldProductName" FieldName="ProductName"
                                     Area="ColumnArea" Caption="Product" />
                <dxpg:PivotGridField Name="fieldExtendedPrice" FieldName="Extended Price"
                                     Area="DataArea" CellFormat="c0" />
            </dxpg:PivotGridControl.Fields>
            <dxpg:PivotGridControl.Groups>
                <dxpg:PivotGridGroup Name="groupCountryCustomer" />
            </dxpg:PivotGridControl.Groups>
        </dxpg:PivotGridControl>
    </Grid>
</Window>
vb
Imports System.Windows
Imports DataSet1
Imports DataSet1TableAdapters
Imports DevExpress.Xpf.PivotGrid

Namespace HowToBindToMDB
    Partial Public Class MainWindow
        Inherits Window
        Private salesPersonDataTable As New SalesPersonDataTable()
        Private salesPersonDataAdapter As New SalesPersonTableAdapter()
        Public Sub New()
            InitializeComponent()
            pivotGridControl1.DataSource = salesPersonDataTable
        End Sub
        Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            salesPersonDataAdapter.Fill(salesPersonDataTable)

            ' Create a group at run-time
            Dim group As PivotGridGroup = pivotGridControl1.Groups.Add(fieldCategoryName, fieldProductName)
        End Sub
    End Class
End Namespace

Inheritance

Object Collection<PivotGridGroup> ObservableCollection<PivotGridGroup> DevExpress.Xpf.PivotGrid.Internal.PivotChildCollection<PivotGridGroup> PivotGridGroupCollection

See Also

PivotGridGroupCollection Members

DevExpress.Xpf.PivotGrid Namespace