Back to Devexpress

PivotField.GroupItems(IEnumerable<Int32>) Method

officefileapi-devexpress-dot-spreadsheet-dot-pivotfield-dot-groupitems-x28-system-dot-collections-dot-generic-dot-ienumerable-system-dot-int32-x29.md

latest6.8 KB
Original Source

PivotField.GroupItems(IEnumerable<Int32>) Method

Groups the specified items in the field.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void GroupItems(
    IEnumerable<int> itemIndices
)
vb
Sub GroupItems(
    itemIndices As IEnumerable(Of Integer)
)

Parameters

NameTypeDescription
itemIndicesIEnumerable<Int32>

A list containing indices of the items to group.

|

Example

View Example

csharp
Worksheet worksheet = workbook.Worksheets["Report11"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];
// Access the "State" field by its name in the collection.
PivotField field = pivotTable.Fields["State"];
// Add the "State" field to the column axis area.
pivotTable.ColumnFields.Add(field);

// Group the first three items in the field.
IEnumerable<int> items = new List<int>() { 0, 1, 2 };
field.GroupItems(items);
// Access the created grouped field by its index in the field collection.
int groupedFieldIndex = pivotTable.Fields.Count - 1;
PivotField groupedField = pivotTable.Fields[groupedFieldIndex];
// Set the grouped item caption to "West".
groupedField.Items[0].Caption = "West";
vb
Dim worksheet As Worksheet = workbook.Worksheets("Report11")
workbook.Worksheets.ActiveWorksheet = worksheet

' Access the pivot table by its name in the collection.
Dim pivotTable As PivotTable = worksheet.PivotTables("PivotTable1")
' Access the "State" field by its name in the collection.
Dim field As PivotField = pivotTable.Fields("State")
' Add the "State" field to the column axis area.
pivotTable.ColumnFields.Add(field)

' Group the first three items in the field.
Dim items As IEnumerable(Of Integer) = New List(Of Integer)() From {0, 1, 2}
field.GroupItems(items)
' Access the created grouped field by its index in the field collection.
Dim groupedFieldIndex As Integer = pivotTable.Fields.Count - 1
Dim groupedField As PivotField = pivotTable.Fields(groupedFieldIndex)
' Set the grouped item caption to "West".
groupedField.Items(0).Caption = "West"

The following code snippets (auto-collected from DevExpress Examples) contain references to the GroupItems(IEnumerable<Int32>) method.

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-spreadsheet-pivot-table-api-examples/CS/SpreadsheetWPFPivotTableExamples/CodeExamples/PivotFieldGroupingActions.cs#L23

csharp
IEnumerable<int> items = new List<int>() { 0, 1, 2 };
field.GroupItems(items);
// Access the created grouped field by its index in the field collection.

winforms-spreadsheet-pivot-table-api/CS/SpreadsheetPivotTableExamples/CodeExamples/PivotFieldGroupingActions.cs#L23

csharp
IEnumerable<int> items = new List<int>() { 0, 1, 2 };
field.GroupItems(items);
// Access the created grouped field by its index in the field collection.

spreadsheet-document-api-pivot-table-examples/CS/SpreadsheetDocServerPivotAPI/CodeExamples/PivotFieldGroupingActions.cs#L29

csharp
IEnumerable<int> items = new List<int>() { 0, 1, 2 };
field.GroupItems(items);
// Access the created grouped field by its index in the field collection.

wpf-spreadsheet-pivot-table-api-examples/VB/SpreadsheetWPFPivotTableExamples/CodeExamples/PivotFieldGroupingActions.vb#L20

vb
Dim items As IEnumerable(Of Integer) = New List(Of Integer)() From {0, 1, 2}
field.GroupItems(items)
' Access the created grouped field by its index in the field collection.

winforms-spreadsheet-pivot-table-api/VB/SpreadsheetPivotTableExamples/CodeExamples/PivotFieldGroupingActions.vb#L20

vb
Dim items As IEnumerable(Of Integer) = New List(Of Integer)() From {0, 1, 2}
field.GroupItems(items)
' Access the created grouped field by its index in the field collection.

spreadsheet-document-api-pivot-table-examples/VB/SpreadsheetDocServerPivotAPI/CodeExamples/PivotFieldGroupingActions.vb#L26

vb
Dim items As IEnumerable(Of Integer) = New List(Of Integer)() From {0, 1, 2}
field.GroupItems(items)
' Access the created grouped field by its index in the field collection.

See Also

PivotField Interface

PivotField Members

DevExpress.Spreadsheet Namespace