Skip to main content
A newer version of this page is available. .

Row.Delete() Method

Deletes a row from a worksheet.

Namespace: DevExpress.Spreadsheet

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

Declaration

void Delete()

Remarks

The Delete method removes the current Row from the Worksheet.Rows collection. Other rows in the worksheet are shifted up. To delete more than one row, use the RowCollection.Remove method.

Note

The number of rows in a worksheet is unchanged - 1,048,576. When you delete rows, 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.

  • Call the Row.Delete method to delete the current row.
  • Call the RowCollection.Remove method of the Worksheet.Rows collection to remove a row at the specified position or delete multiple rows at once.
  • To delete a row containing the specified cell or multiple rows containing the specified cell range, use the Worksheet.DeleteCells method with DeleteMode.EntireRow enumeration member passed as a parameter.

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.

// 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);
See Also