Back to Devexpress

CellRange.Offset(Int32, Int32) Method

officefileapi-devexpress-dot-spreadsheet-dot-cellrange-dot-offset-x28-system-dot-int32-system-dot-int32-x29.md

latest7.0 KB
Original Source

CellRange.Offset(Int32, Int32) Method

Returns a cell range that is a given number of rows and columns from the current range.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
CellRange Offset(
    int rowCount,
    int columnCount
)
vb
Function Offset(
    rowCount As Integer,
    columnCount As Integer
) As CellRange

Parameters

NameTypeDescription
rowCountInt32

The number of rows by which the cell range should be offset (positive value—range is offset down, negative value—range is offset up, zero—range is not offset vertically).

| | columnCount | Int32 |

The number of columns by which the cell range should be offset (positive value—range is offset to the right, negative value—range is offset to the left, zero—range is not offset horizontally).

|

Returns

TypeDescription
CellRange

The cell range that is offset from the current range.

|

Remarks

Use the Offset method to access a cell range that has the same size as the current range, but is moved from the current range by the specified number of rows and columns.

The Offset method below returns a cell range that is five rows below and two columns to the left of the cell range “D3:F6”.

csharp
CellRange offset = worksheet["D3:F6"].Offset(5, -2);
vb
Dim offset As CellRange = worksheet("D3:F6").Offset(5, -2)

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

wpf-spreadsheet-chart-api/CS/SpreadsheetWPFChartAPISamples/MainWindow.xaml.cs#L60

csharp
CellRange usedRange = firstSheet.GetUsedRange();
firstSheet.SelectedCell = usedRange[usedRange.RowCount * usedRange.ColumnCount - 1].Offset(1, 1);

wpf-spreadsheet-pivot-table-api-examples/CS/SpreadsheetWPFPivotTableExamples/MainWindow.xaml.cs#L52

csharp
CellRange usedRange = firstSheet.GetUsedRange();
firstSheet.SelectedCell = usedRange[usedRange.RowCount * usedRange.ColumnCount - 1].Offset(1, 1);

winforms-spreadsheet-use-custom-cell-editors/CS/DevAVInvoicing/Form1.cs#L199

csharp
void MoveUpLastRecord(CellRange itemRange) {
    CellRange range = itemRange.Offset(-1, 0);
    range.CopyFrom(itemRange, PasteSpecial.All, true);

winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/Form1.cs#L119

csharp
CellRange usedRange =active.GetUsedRange();
    active.SelectedCell = usedRange[usedRange.RowCount * usedRange.ColumnCount - 1].Offset(1, 1);
}

winforms-spreadsheet-pivot-table-api/CS/SpreadsheetPivotTableExamples/Form1.cs#L107

csharp
CellRange usedRange = active.GetUsedRange();
active.SelectedCell = usedRange[usedRange.RowCount * usedRange.ColumnCount - 1].Offset(1, 1);

wpf-spreadsheet-chart-api/VB/SpreadsheetWPFChartAPISamples/MainWindow.xaml.vb#L62

vb
Dim usedRange As CellRange = firstSheet.GetUsedRange()
firstSheet.SelectedCell = usedRange(usedRange.RowCount * usedRange.ColumnCount - 1).Offset(1, 1)

wpf-spreadsheet-pivot-table-api-examples/VB/SpreadsheetWPFPivotTableExamples/MainWindow.xaml.vb#L51

vb
Dim usedRange As CellRange = firstSheet.GetUsedRange()
firstSheet.SelectedCell = usedRange(usedRange.RowCount * usedRange.ColumnCount - 1).Offset(1, 1)

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

vb
Private Sub MoveUpLastRecord(ByVal itemRange As CellRange)
    Dim range As CellRange = itemRange.Offset(-1, 0)
    range.CopyFrom(itemRange, PasteSpecial.All, True)

winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/Form1.vb#L115

vb
Dim usedRange As CellRange = active.GetUsedRange()
    active.SelectedCell = usedRange(usedRange.RowCount * usedRange.ColumnCount - 1).Offset(1, 1)
End If

winforms-spreadsheet-pivot-table-api/VB/SpreadsheetPivotTableExamples/Form1.vb#L102

vb
Dim usedRange As CellRange = active.GetUsedRange()
active.SelectedCell = usedRange(usedRange.RowCount * usedRange.ColumnCount - 1).Offset(1, 1)

See Also

CellRange Interface

CellRange Members

DevExpress.Spreadsheet Namespace