Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

PivotFieldReferenceCollection.Insert(Int32, PivotField) Method

Inserts a row or column field into the collection at the specified index.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.1.Core.dll

Declaration

PivotFieldReference Insert(
    int index,
    PivotField field
)

Parameters

Name Type Description
index Int32

A zero-based integer which specifies the position at which the field should be inserted.

field PivotField

A PivotField object representing the field to insert into the collection.

Returns

Type Description
PivotFieldReference

A PivotFieldReference object which represents the inserted row or column field.

Remarks

Use the Insert method to add a new field to the PivotTable’s row axis area (or column axis area) at the specified position.

If the index parameter is negative or exceeds the number of elements within the collection, a ArgumentOutOfRangeException exception is raised. When inserting a new field, the row (or column) fields that follow the insertion point move down to accommodate the new field. The indexes of the moved fields are updated as well.

To add a new row (or column) field to the end of the PivotTable.RowFields (or PivotTable.ColumnFields) collection, use the PivotFieldReferenceCollection.Add method. To remove a row (or column) field from the collection, use the PivotFieldReferenceCollection.Remove or PivotFieldReferenceCollection.RemoveAt method. You can also use the PivotFieldReferenceCollection.Clear method to remove all fields from the PivotTable’s row axis area (or column axis area).

Example

Dim worksheet As Worksheet = workbook.Worksheets("Report1")
workbook.Worksheets.ActiveWorksheet = worksheet

' Access the pivot table by its name in the collection.
Dim pivotTable As PivotTable = worksheet.PivotTables("PivotTable1")

' Insert the "Region" field at the top of the row axis area.
pivotTable.RowFields.Insert(0, pivotTable.Fields("Region"))

The following code snippets (auto-collected from DevExpress Examples) contain references to the Insert(Int32, PivotField) 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.

See Also