PivotGridGroupCollection.Add(PivotGridField[]) Method
Copies fields from the specified array to a new group and assigns the group to the collection.
Namespace: DevExpress.Xpf.PivotGrid
Assembly: DevExpress.Xpf.PivotGrid.v18.2.dll
Declaration
public PivotGridGroup Add(
params PivotGridField[] fields
)
Public Function Add(
ParamArray fields As PivotGridField()
) As PivotGridGroup
Parameters
Name |
Type |
Description |
fields |
PivotGridField[] |
An array of PivotGridField objects, representing the fields that should be added to a new group.
|
Returns
Example
The following example demonstrates how to combine fields into a group.
In this example, three fields (“Country”, “Region” and “City”) are combined in a new group, in this order. This ensures that the “Country” field is followed by “Region”, which is in turn followed by “City”. If the “Region” field is dragged to another area, the other fields accompany it.
using System.Windows;
using DevExpress.Xpf.PivotGrid;
using HowToBindToMDB.NwindDataSetTableAdapters;
namespace HowToBindToMDB {
public partial class MainWindow : Window {
NwindDataSet.SalesPersonDataTable salesPersonDataTable =
new NwindDataSet.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);
}
}
}
<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 HorizontalAlignment="Left" Name="pivotGridControl1"
VerticalAlignment="Top">
<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="Product Category" />
<dxpg:PivotGridField Name="fieldProductName" FieldName="ProductName"
Area="ColumnArea" Caption="Product Name" />
<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>
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid
Imports HowToBindToMDB.NwindDataSetTableAdapters
Namespace HowToBindToMDB
Partial Public Class MainWindow
Inherits Window
Private salesPersonDataTable As New NwindDataSet.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
See Also