Back to Devexpress

RowCollection.Remove(Int32, Int32) Method

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

latest8.6 KB
Original Source

RowCollection.Remove(Int32, Int32) Method

Removes multiple rows from the worksheet.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

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

Parameters

NameTypeDescription
indexInt32

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

| | count | Int32 |

Specifies the number of rows to remove.

|

Remarks

The number of rows in a worksheet is unchanged - 1,048,576. When you delete rows, other rows in the worksheet are shifted up and the equivalent number of new rows is automatically added to the end of the worksheet’s row collection.

If you need to delete only the cell content or formatting from rows without removing entire rows 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 rows without deleting them from the worksheet. To do this, use the Row.Visible property (see the How to: Hide a Row or a Column example).

Example

This example demonstrates how to remove rows from a worksheet.

When you delete rows from a worksheet, other rows are automatically shifted up.

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

View Example

csharp
// Delete the 2nd row from the worksheet.
worksheet.Rows[1].Delete();

// Delete the 3rd row from the worksheet.
worksheet.Rows.Remove(2);

// Delete three rows from the worksheet starting from the 10th row.
worksheet.Rows.Remove(9, 3);

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

' Delete the 3rd row from the worksheet.
worksheet.Rows.Remove(2)

' Delete three rows from the worksheet starting from the 10th row.
worksheet.Rows.Remove(9, 3)

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

The following code snippets (auto-collected from DevExpress Examples) contain references to the Remove(Int32, 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-spreadsheet-use-custom-cell-editors/CS/DevAVInvoicing/Form1.cs#L161

csharp
spreadsheetControl1.CloseCellEditor(CellEditorEnterValueMode.Cancel);
sheet.Rows.Remove(sheet.SelectedCell.TopRowIndex, 1);
EnableControls();

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

csharp
// Delete three rows from the worksheet starting from the tenth row.
worksheet.Rows.Remove(9, 3);

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

csharp
// Delete three rows from the worksheet starting from the 10th row.
worksheet.Rows.Remove(9, 3);

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

csharp
// Delete three rows (from row 10 to row 12).
worksheet.Rows.Remove(9, 3);

winforms-spreadsheet-use-custom-cell-editors/VB/DevAVInvoicing/Form1.vb#L149

vb
If spreadsheetControl1.IsCellEditorActive Then spreadsheetControl1.CloseCellEditor(CellEditorEnterValueMode.Cancel)
sheet.Rows.Remove(sheet.SelectedCell.TopRowIndex, 1)
EnableControls()

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

vb
' Delete three rows from the worksheet starting from the tenth row.
worksheet.Rows.Remove(9, 3)

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

vb
' Delete three rows from the worksheet starting from the 10th row.
worksheet.Rows.Remove(9, 3)

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

vb
' Delete three rows (from row 10 to row 12).
worksheet.Rows.Remove(9, 3)
' Delete a row that contains the "B2" cell.

See Also

Delete()

DeleteCells

Rows and Columns in Spreadsheet Documents

RowCollection Interface

RowCollection Members

DevExpress.Spreadsheet Namespace