Back to Devexpress

ColumnCollection.Remove(Int32) Method

officefileapi-devexpress-dot-spreadsheet-dot-columncollection-dot-remove-x28-system-dot-int32-x29.md

latest7.6 KB
Original Source

ColumnCollection.Remove(Int32) Method

Removes the column at the specified position from the worksheet.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void Remove(
    int index
)
vb
Sub Remove(
    index As Integer
)

Parameters

NameTypeDescription
indexInt32

A zero-based index of the column to remove. If it is negative or exceeds the last available index (16383), an exception occurs.

|

Remarks

The number of columns in a worksheet is unchanged - 16,384. When you delete columns, other columns in the worksheet are shifted to the left and the equivalent number of new columns is automatically added to the end of the worksheet’s column collection.

If you need to delete only the cell content or formatting from columns without removing entire columns from the worksheet, use the Clear* methods of the Worksheet object (see the How to: Clear Cells of Content, Formatting, Hyperlinks and Comments example).

You can also hide unnecessary columns without deleting them from the worksheet. To do this, use the Column.Visible property (see the How to: Hide a Row or a Column example).

Example

This example demonstrates how to remove columns from a worksheet.

When you delete columns from a worksheet, other columns are automatically shifted to the left.

Enclose your code in the Workbook.BeginUpdate - Workbook.EndUpdate method calls to improve performance when you remove multiple columns from a document.

View Example

csharp
// Delete the 2nd column from the worksheet.
worksheet.Columns[1].Delete();

// Delete the 3rd column from the worksheet.
worksheet.Columns.Remove(2);

// Delete three columns from the worksheet starting from the 10th column.
worksheet.Columns.Remove(9, 3);

// Delete a column that contains the "B2"cell.
worksheet.DeleteCells(worksheet.Cells["B2"], DeleteMode.EntireColumn);
vb
' Delete the 2nd column from the worksheet.
worksheet.Columns(1).Delete()

' Delete the 3rd column from the worksheet.
worksheet.Columns.Remove(2)

' Delete three columns from the worksheet starting from the 10th column.
worksheet.Columns.Remove(9, 3)

' Delete a column that contains the "B2"cell.
worksheet.DeleteCells(worksheet.Cells("B2"), DeleteMode.EntireColumn)

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

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/RowAndColumnActions.cs#L89

csharp
// Delete the third column from the worksheet.
worksheet.Columns.Remove(2);

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/RowAndColumnActions.cs#L90

csharp
// Delete the 3rd column from the worksheet.
worksheet.Columns.Remove(2);

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.cs#L86

csharp
// Delete the third column.
worksheet.Columns.Remove(2);

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/RowAndColumnActions.vb#L92

vb
' Delete the third column from the worksheet.
worksheet.Columns.Remove(2)

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/RowAndColumnActions.vb#L92

vb
' Delete the 3rd column from the worksheet.
worksheet.Columns.Remove(2)

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.vb#L70

vb
' Delete the third column.
worksheet.Columns.Remove(2)
' Delete three columns (from column "J" to column "L").

See Also

Delete()

DeleteCells

Rows and Columns in Spreadsheet Documents

ColumnCollection Interface

ColumnCollection Members

DevExpress.Spreadsheet Namespace