wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridfield-1736b224.md
Gets or sets the field’s index among the other fields displayed within the same area. This is a dependency property.
Namespace : DevExpress.Xpf.PivotGrid
Assembly : DevExpress.Xpf.PivotGrid.v25.2.dll
NuGet Package : DevExpress.Wpf.PivotGrid
public int AreaIndex { get; set; }
Public Property AreaIndex As Integer
| Type | Description |
|---|---|
| Int32 |
A zero-based integer that specifies the field’s index among the other fields displayed within the same area.
|
A field can be placed within one of four areas: Filter Header Area, Column Header Area, Row Header Area or Data Header Area. The AreaIndex property specifies the field’s index among the other fields displayed within the same area.
If the current field is hidden, assigning a positive value to the AreaIndex property makes the field visible. If the field is visible, assigning a negative value to this property will hide the field and will set its AreaIndex property to -1.
Use the PivotGridField.Area property to specify the area in which the field is displayed. The field’s position can also be set via the PivotGridField.SetAreaPosition method.
Dragging a field from one area to another automatically changes the AreaIndex property’s value, and vice versa. Before the field’s location is changed, the DXPivotGrid fires the PivotGridControl.FieldAreaChanging event, allowing you to cancel the action. After the location has been changed, the PivotGridControl.FieldAreaChanged event is fired.
Multiple fields can be combined into a group via the PivotGridControl.Groups property. These fields cannot be separated and are always dragged together. To move a group to a specific area or to a new position within the current area, use the PivotGridField.Area and AreaIndex properties of the first field in the group. Modifying the PivotGridField.Area and AreaIndex properties for the second and subsequent fields in the group is ignored.
The following example demonstrates how to bind the PivotGridControl to a “SalesPerson” view in the nwind.mdb database, which ships with the installation.
Follow the steps below to connect the Pivot Grid to a database.
OleDbDataAdapter instance to select records from the data source.DataSet object and populate it with data.Follow the steps below to create and configure Pivot Grid fields.
PivotGridField.AreaIndex properties. AreaIndex can be set only after the field is added to the control’s field collection.DataSourceColumnBinding object to the field’s PivotGridField.DataBinding property.Note that if you want to see an example of how to add pivot grid fields in XAML, please refer to the following tutorial: How to: Bind a PivotGrid to an MS Access Database.
using System.Data;
using System.Data.OleDb;
using System.Windows;
using DevExpress.Xpf.PivotGrid;
namespace HowToBindToMDB {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
// Create a connection object.
OleDbConnection connection =
new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB");
// Create a data adapter.
OleDbDataAdapter adapter =
new OleDbDataAdapter("SELECT * FROM SalesPerson", connection);
// Create and fill a dataset.
DataSet sourceDataSet = new DataSet();
adapter.Fill(sourceDataSet, "SalesPerson");
// Assign the data source to the PivotGrid control.
pivotGridControl1.DataSource = sourceDataSet.Tables["SalesPerson"];
pivotGridControl1.DataProcessingEngine = DataProcessingEngine.Optimized;
pivotGridControl1.BeginUpdate();
// Create a row pivot grid field bound to the Country data source column.
PivotGridField fieldCountry = new PivotGridField();
fieldCountry.Caption = "Country";
fieldCountry.Area = FieldArea.RowArea;
DataSourceColumnBinding countryBinding = new DataSourceColumnBinding("Country");
fieldCountry.DataBinding = countryBinding;
// Create a row pivot grid field bound to the Sales Person data source column.
PivotGridField fieldCustomer = new PivotGridField();
fieldCustomer.Caption = "Customer";
fieldCustomer.Area = FieldArea.RowArea;
DataSourceColumnBinding customerBinding = new DataSourceColumnBinding("Sales Person");
fieldCustomer.DataBinding = customerBinding;
// Create a column pivot grid field bound to the OrderDate data source column.
PivotGridField fieldYear = new PivotGridField();
fieldYear.Caption = "Year";
fieldYear.Area = FieldArea.ColumnArea;
DataSourceColumnBinding fieldOrderDate1Binding = new DataSourceColumnBinding("OrderDate");
fieldOrderDate1Binding.GroupInterval = FieldGroupInterval.DateYear;
fieldYear.DataBinding = fieldOrderDate1Binding;
// Create a column pivot grid field bound to the CategoryName data source column.
PivotGridField fieldCategoryName = new PivotGridField();
fieldCategoryName.Caption = "Product Category";
fieldCategoryName.Area = FieldArea.ColumnArea;
DataSourceColumnBinding categoryNameBinding = new DataSourceColumnBinding("CategoryName");
fieldCategoryName.DataBinding = categoryNameBinding;
// Create a filter pivot grid field bound to the ProductName data source column.
PivotGridField fieldProductName = new PivotGridField();
fieldProductName.Caption = "Product Name";
fieldProductName.Area = FieldArea.FilterArea;
DataSourceColumnBinding productNameBinding = new DataSourceColumnBinding("ProductName");
fieldProductName.DataBinding = productNameBinding;
// Create a data pivot grid field bound to the 'Extended Price' data source column.
PivotGridField fieldExtendedPrice = new PivotGridField();
fieldExtendedPrice.Area = FieldArea.DataArea;
DataSourceColumnBinding extendedPriceBinding = new DataSourceColumnBinding("Extended Price");
fieldExtendedPrice.DataBinding = extendedPriceBinding;
// Specify the formatting setting to format summary values as integer currency amount.
fieldExtendedPrice.CellFormat = "c0";
// Add the fields to the control's field collection.
pivotGridControl1.Fields.AddRange(fieldCountry, fieldCustomer,
fieldCategoryName, fieldProductName, fieldYear, fieldExtendedPrice);
// Arrange the row fields within the Row Header Area.
fieldCountry.AreaIndex = 0;
fieldCustomer.AreaIndex = 1;
// Arrange the column fields within the Column Header Area.
fieldCategoryName.AreaIndex = 0;
fieldYear.AreaIndex = 1;
pivotGridControl1.EndUpdate();
}
}
}
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid
Namespace HowToBindToMDB
Public Partial Class MainWindow
Inherits Window
Public Sub New()
Me.InitializeComponent()
End Sub
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Create a connection object.
Dim connection As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB")
' Create a data adapter.
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM SalesPerson", connection)
' Create and fill a dataset.
Dim sourceDataSet As DataSet = New DataSet()
adapter.Fill(sourceDataSet, "SalesPerson")
' Assign the data source to the PivotGrid control.
Me.pivotGridControl1.DataSource = sourceDataSet.Tables("SalesPerson")
Me.pivotGridControl1.DataProcessingEngine = DataProcessingEngine.Optimized
Me.pivotGridControl1.BeginUpdate()
' Create a row pivot grid field bound to the Country data source column.
Dim fieldCountry As PivotGridField = New PivotGridField()
fieldCountry.Caption = "Country"
fieldCountry.Area = FieldArea.RowArea
Dim countryBinding As DataSourceColumnBinding = New DataSourceColumnBinding("Country")
fieldCountry.DataBinding = countryBinding
' Create a row pivot grid field bound to the Sales Person data source column.
Dim fieldCustomer As PivotGridField = New PivotGridField()
fieldCustomer.Caption = "Customer"
fieldCustomer.Area = FieldArea.RowArea
Dim customerBinding As DataSourceColumnBinding = New DataSourceColumnBinding("Sales Person")
fieldCustomer.DataBinding = customerBinding
' Create a column pivot grid field bound to the OrderDate data source column.
Dim fieldYear As PivotGridField = New PivotGridField()
fieldYear.Caption = "Year"
fieldYear.Area = FieldArea.ColumnArea
Dim fieldOrderDate1Binding As DataSourceColumnBinding = New DataSourceColumnBinding("OrderDate")
fieldOrderDate1Binding.GroupInterval = FieldGroupInterval.DateYear
fieldYear.DataBinding = fieldOrderDate1Binding
' Create a column pivot grid field bound to the CategoryName data source column.
Dim fieldCategoryName As PivotGridField = New PivotGridField()
fieldCategoryName.Caption = "Product Category"
fieldCategoryName.Area = FieldArea.ColumnArea
Dim categoryNameBinding As DataSourceColumnBinding = New DataSourceColumnBinding("CategoryName")
fieldCategoryName.DataBinding = categoryNameBinding
' Create a filter pivot grid field bound to the ProductName data source column.
Dim fieldProductName As PivotGridField = New PivotGridField()
fieldProductName.Caption = "Product Name"
fieldProductName.Area = FieldArea.FilterArea
Dim productNameBinding As DataSourceColumnBinding = New DataSourceColumnBinding("ProductName")
fieldProductName.DataBinding = productNameBinding
' Create a data pivot grid field bound to the 'Extended Price' data source column.
Dim fieldExtendedPrice As PivotGridField = New PivotGridField()
fieldExtendedPrice.Area = FieldArea.DataArea
Dim extendedPriceBinding As DataSourceColumnBinding = New DataSourceColumnBinding("Extended Price")
fieldExtendedPrice.DataBinding = extendedPriceBinding
' Specify the formatting setting to format summary values as integer currency amount.
fieldExtendedPrice.CellFormat = "c0"
' Add the fields to the control's field collection.
Me.pivotGridControl1.Fields.AddRange(fieldCountry, fieldCustomer, fieldCategoryName, fieldProductName, fieldYear, fieldExtendedPrice)
' Arrange the row fields within the Row Header Area.
fieldCountry.AreaIndex = 0
fieldCustomer.AreaIndex = 1
' Arrange the column fields within the Column Header Area.
fieldCategoryName.AreaIndex = 0
fieldYear.AreaIndex = 1
Me.pivotGridControl1.EndUpdate()
End Sub
Run the project and see the result:
The following code snippets (auto-collected from DevExpress Examples) contain references to the AreaIndex property.
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.
<dxpg:PivotGridField Area="RowArea"
Name="fieldCountry" AreaIndex="0">
<dxpg:PivotGridField.DataBinding>
wpf-pivot-grid-implement-custom-summary/CS/DXPivotGrid_CustomSummary/MainWindow.xaml#L14
<dxpg:PivotGridControl.Fields>
<dxpg:PivotGridField Name="fieldCategoryName" Area="RowArea" AreaIndex="0" Caption="Category Name">
<dxpg:PivotGridField.DataBinding>
Area="RowArea"
AreaIndex="0"
Caption="Category Name">
wpf-pivotgrid-customize-the-cell-template/CS/HowToCustomizeCellTemplate/MainWindow.xaml#L39
Area="RowArea"
AreaIndex="0"
Caption="Category">
Area="RowArea"
AreaIndex="0"
Caption="Category">
wpf-pivot-grid-bind-to-an-mdb-database/CS/HowToBindToMDB/MainWindow.xaml.cs#L49
field.DataBinding = new DataSourceColumnBinding(columnName);
field.AreaIndex = index;
}
wpf-pivot-grid-bind-to-an-olap-cube-net6/CS/HowToBindOLAP/MainWindow.xaml.cs#L51
field.DataBinding = new DataSourceColumnBinding(fieldName);
field.AreaIndex = index;
return field;
wpf-pivot-grid-hide-specific-columns-and-row/CS/WpfApp/Data.cs#L23
pivot.Fields.AddDataSourceColumn(Widget, FieldArea.RowArea);
pivot.Fields.AddDataSourceColumn(Month, FieldArea.ColumnArea).AreaIndex = 0;
pivot.Fields.AddDataSourceColumn(RetailPrice, FieldArea.DataArea);
wpf-pivot-grid-split-field-value-cells/CS/Data.cs#L23
pivot.Fields.AddDataSourceColumn(Widget, FieldArea.RowArea);
pivot.Fields.AddDataSourceColumn(Month, FieldArea.ColumnArea).AreaIndex = 0;
pivot.Fields.AddDataSourceColumn(RetailPrice, FieldArea.DataArea);
{
var fields = valueItem.PivotGrid.GetFieldsByArea(valueItem.IsColumn ? FieldArea.ColumnArea : FieldArea.RowArea).Where(f => f.AreaIndex <= valueItem.Field.AreaIndex);
return fields.
wpf-pivot-grid-bind-to-an-mdb-database/VB/HowToBindToMDB/MainWindow.xaml.vb#L44
field.DataBinding = New DataSourceColumnBinding(columnName)
field.AreaIndex = index
End Sub
wpf-pivot-grid-bind-to-an-olap-cube-net6/VB/HowToBindOLAP/MainWindow.xaml.vb#L47
End If
field.AreaIndex = index
Return field
wpf-pivot-grid-hide-specific-columns-and-row/VB/WpfApp/Data.vb#L26
pivot.Fields.AddDataSourceColumn(Widget, FieldArea.RowArea)
pivot.Fields.AddDataSourceColumn(Month, FieldArea.ColumnArea).AreaIndex = 0
pivot.Fields.AddDataSourceColumn(RetailPrice, FieldArea.DataArea)
wpf-pivot-grid-split-field-value-cells/VB/Data.vb#L35
pivot.Fields.AddDataSourceColumn(Widget, FieldArea.RowArea)
pivot.Fields.AddDataSourceColumn(Month, FieldArea.ColumnArea).AreaIndex = 0
pivot.Fields.AddDataSourceColumn(RetailPrice, FieldArea.DataArea)
Private Shared Function GetConditions(ByVal valueItem As FieldValueElementData) As List(Of KeyValuePair(Of PivotGridField, Object))
Dim fields = valueItem.PivotGrid.GetFieldsByArea(If(valueItem.IsColumn, FieldArea.ColumnArea, FieldArea.RowArea)).Where(Function(f) f.AreaIndex <= valueItem.Field.AreaIndex)
Return fields.Select(Function(f) New KeyValuePair(Of PivotGridField, Object)(f, valueItem.PivotGrid.GetFieldValue(f, valueItem.MinIndex))).ToList()
See Also