# Field Groups | WPF Controls | DevExpress Documentation

The [Pivot Grid](/WPF/7228/controls-and-libraries/pivot-grid) provides the capability to arrange [fields](/WPF/8024/controls-and-libraries/pivot-grid/fundamentals/fields) into **groups**. End-users cannot separate grouped fields by dragging one of them to a different area or by hiding it in the [field list](/WPF/8018/controls-and-libraries/pivot-grid/layout/customization-form).

![pivotgrid_groups](/WPF/images/pivotgrid_groups11539.png)

[Run Demo: Groups](dxdemo://Wpf/DXPivotGrid/MainDemo/Groups)

## Create a Field Group

Do the following to create a new group:

1. Create a [PivotGridGroup](/WPF/DevExpress.Xpf.PivotGrid.PivotGridGroup) descendant and add it to the [PivotGridControl.Groups](/WPF/DevExpress.Xpf.PivotGrid.PivotGridControl.Groups) collection, which stores the Pivot Grid’s field groups.
2. You can define a new group in two ways:

    - Use the field’s [PivotGridField.Group](/WPF/DevExpress.Xpf.PivotGrid.PivotGridField.Group) property to bind fields to the group.
    - Use the field’s [PivotGridField.GroupName](/WPF/DevExpress.Xpf.PivotGrid.PivotGridField.GroupName) property to specify the group’s name.
3. Set the [PivotGridField.GroupIndex](/WPF/DevExpress.Xpf.PivotGrid.PivotGridField.GroupIndex) property to specify a field’s index in the group.

## Field Group Settings

To move a group to a specific area or new position within the current area, use the [PivotGridField.Area](/WPF/DevExpress.Xpf.PivotGrid.PivotGridField.Area) and [PivotGridField.AreaIndex](/WPF/DevExpress.Xpf.PivotGrid.PivotGridField.AreaIndex) properties of the first field in the group. Setting these properties for the second and subsequent fields in the group has no effect.

A Group Expand button allows you to collapse and expand the grouped field. Collapsing/expanding a grouped field header hides/shows columns or rows that correspond to grouped child fields.

![pivotgrid_collapsegroups](/WPF/images/pivotgrid_collapsegroups11540.png)

To set the expansion status of grouped fields in code, use the [PivotGridField.ExpandedInFieldsGroup](/WPF/DevExpress.Xpf.PivotGrid.PivotGridField.ExpandedInFieldsGroup) property.

## Member Table

| Property | Description |
| --- | --- |
| [PivotGridControl.Groups](/WPF/DevExpress.Xpf.PivotGrid.PivotGridControl.Groups) | Gets the collection of field groups. |
| [PivotGridField.Group](/WPF/DevExpress.Xpf.PivotGrid.PivotGridField.Group) | Gets or sets the group which owns the current field. |
| [PivotGridField.GroupName](/WPF/DevExpress.Xpf.PivotGrid.PivotGridField.GroupName) | Gets or sets the group name of the current field. |
| [PivotGridField.GroupIndex](/WPF/DevExpress.Xpf.PivotGrid.PivotGridField.GroupIndex) | Gets or sets the field’s index in a group. |
| [PivotGridField.ExpandedInFieldsGroup](/WPF/DevExpress.Xpf.PivotGrid.PivotGridField.ExpandedInFieldsGroup) | Gets or sets the current field’s expansion status it belongs to a group. |

## Example: How to Arrange Fields into a Group

The following example demonstrates how to combine [fields](/WPF/8024/controls-and-libraries/pivot-grid/fundamentals/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.

![](/WPF/images/pivot-grid-group-fields-example.png)

- MainWindow.xaml.cs
- MainWindow.xaml
- MainWindow.xaml.vb

<section id="tabpanel_OLJpswH4tv_tabid-csharpMainWindow-xaml-cs" role="tabpanel" data-tab="tabid-csharpMainWindow-xaml-cs">
<pre><code data-code-links="{&quot;/ (System.Windows)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows&quot;,&quot;/ (DevExpress.Xpf.PivotGrid)(?:;|$)/&quot;:&quot;/WPF/DevExpress.Xpf.PivotGrid&quot;}" class="lang-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);
        }
    }
}
</code></pre></section>
<section id="tabpanel_OLJpswH4tv_tabid-xamlMainWindow-xaml" role="tabpanel" data-tab="tabid-xamlMainWindow-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;Window x:Class=&quot;HowToBindToMDB.MainWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        xmlns:dxpg=&quot;http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid&quot;
        Title=&quot;MainWindow&quot; Height=&quot;350&quot; Width=&quot;525&quot;  Loaded=&quot;Window_Loaded&quot;&gt;
    &lt;Grid&gt;
        &lt;dxpg:PivotGridControl Name=&quot;pivotGridControl1&quot;&gt;
            &lt;dxpg:PivotGridControl.Fields&gt;
                &lt;dxpg:PivotGridField Name=&quot;fieldCountry&quot; FieldName=&quot;Country&quot; Area=&quot;RowArea&quot; 
                                     Group=&quot;{Binding ElementName=groupCountryCustomer}&quot; /&gt;
                &lt;dxpg:PivotGridField Name=&quot;fieldCustomer&quot; FieldName=&quot;Sales Person&quot; Area=&quot;RowArea&quot; 
                                     Group=&quot;{Binding ElementName=groupCountryCustomer}&quot; 
                                     Caption=&quot;Customer&quot;/&gt;
                &lt;dxpg:PivotGridField Name=&quot;fieldYear&quot; FieldName=&quot;OrderDate&quot; Area=&quot;FilterArea&quot;
                                     Caption=&quot;Year&quot; GroupInterval=&quot;DateYear&quot; /&gt;
                &lt;dxpg:PivotGridField Name=&quot;fieldCategoryName&quot; FieldName=&quot;CategoryName&quot;
                                     Area=&quot;ColumnArea&quot; Caption=&quot;Category&quot; /&gt;
                &lt;dxpg:PivotGridField Name=&quot;fieldProductName&quot; FieldName=&quot;ProductName&quot;
                                     Area=&quot;ColumnArea&quot; Caption=&quot;Product&quot; /&gt;
                &lt;dxpg:PivotGridField Name=&quot;fieldExtendedPrice&quot; FieldName=&quot;Extended Price&quot;
                                     Area=&quot;DataArea&quot; CellFormat=&quot;c0&quot; /&gt;
            &lt;/dxpg:PivotGridControl.Fields&gt;
            &lt;dxpg:PivotGridControl.Groups&gt;
                &lt;dxpg:PivotGridGroup Name=&quot;groupCountryCustomer&quot; /&gt;
            &lt;/dxpg:PivotGridControl.Groups&gt;
        &lt;/dxpg:PivotGridControl&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;
</code></pre></section>
<section id="tabpanel_OLJpswH4tv_tabid-vbMainWindow-xaml-vb" role="tabpanel" data-tab="tabid-vbMainWindow-xaml-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (System.Windows)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows&quot;,&quot;/ (DevExpress.Xpf.PivotGrid)(?:;|$)/&quot;:&quot;/WPF/DevExpress.Xpf.PivotGrid&quot;}" class="lang-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)

            &#39; Create a group at run-time
            Dim group As PivotGridGroup = pivotGridControl1.Groups.Add(fieldCategoryName, fieldProductName)
        End Sub
    End Class
End Namespace
</code></pre></section>