Skip to main content
All docs
V25.1
  • Row

    CellRange.Resize(Int32, Int32) Method

    Resizes the current cell range.

    Namespace: DevExpress.Spreadsheet

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

    NuGet Package: DevExpress.Spreadsheet.Core

    Declaration

    CellRange Resize(
        int rowCount,
        int columnCount
    )

    Parameters

    Name Type Description
    rowCount Int32

    The number of rows in the new range.

    columnCount Int32

    The number of columns in the new range.

    Returns

    Type Description
    CellRange

    The resized cell range.

    Remarks

    Use the Resize method to enlarge or reduce a cell range within a worksheet. This method always takes the range’s top left cell as its starting point. If the resulting range’s height or width is less than one cell or exceeds the maximum number of rows or columns in a worksheet, the Spreadsheet throws an InvalidOperationException.

    The following example demonstrates how to extend selection within the Spreadsheet control by one row and one column:

    CellRange selection = spreadsheetControl1.Selection;
    selection.Resize(selection.RowCount + 1, selection.ColumnCount + 1).Select();
    

    You can use the Resize method for a union range only if it meets the following requirements:

    • Its subranges start at the same column and have the same width (for example, “B2:D4, B7:D8”).

      Spreadsheet_Resize_Horizontal_UnionRange

      In this case, you can change the number of columns in the subranges:

      CellRange unionRange = worksheet.Range.Union(worksheet["B2:D4"], worksheet["B7:D8"]);
      CellRange resizedRange = unionRange.Resize(unionRange.RowCount, unionRange.ColumnCount+1);
      

      The image below shows the resized complex range.

      Spreadsheet_Resize_Horizontal_UnionRange_Resized

    • Its subranges start at the same row and have the same height (for example, “B2:C7, E2:E7”):

      Spreadsheet_Resize_Vertical_UnionRange

      In this case, you can change the number of rows in the subranges:

      CellRange unionRange = worksheet.Range.Union(worksheet["B2:C7"], worksheet["E2:E7"]);
      CellRange resizedRange = unionRange.Resize(unionRange.RowCount+1, unionRange.ColumnCount);
      

      The image below shows the resized complex range.

      Spreadsheet_Resize_Vertical_UnionRange_Resized

    For other types of union ranges, the Resize method throws an InvalidOperationException.

    See Also