Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Delete a Cell or Range of Cells

Tip

A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e4938/wpf-spreadsheetcontrol-api-part-1.

This example demonstrates how to delete cells from a worksheet. To do this, use the Worksheet.DeleteCells method. Pass the cell or cell range that you wish to delete, and the DeleteMode.ShiftCellsUp or DeleteMode.ShiftCellsLeft enumeration member to specify how other cells should be shifted.

using DevExpress.Spreadsheet;
// ...

Workbook workbook = spreadsheetControl1.Document;
Worksheet worksheet = workbook.Worksheets[0];

// Delete the C5 cell, shifting other cells in the same row to the left.
worksheet.DeleteCells(worksheet.Cells["C5"], DeleteMode.ShiftCellsLeft);

// Delete the H11:I12 range of cells, shifting other cells in the same column up.
worksheet.DeleteCells(worksheet.Range["H11:I12"], DeleteMode.ShiftCellsUp);