Skip to main content

SpreadsheetControl.GetSelectedRanges() Method

Returns cell ranges currently selected in the active worksheet.

Namespace: DevExpress.XtraSpreadsheet

Assembly: DevExpress.XtraSpreadsheet.v24.1.dll

NuGet Package: DevExpress.Win.Spreadsheet

Declaration

public IList<CellRange> GetSelectedRanges()

Returns

Type Description
IList<CellRange>

A list of the CellRange objects.

Remarks

The SpreadsheetControl.Selection property specifies the range of cells selected in the active worksheet. The SpreadsheetControl.SelectedCell property specifies a cell where data is inserted when an end-user types (in other words, this is an active cell that can also be obtained via the SpreadsheetControl.ActiveCell property). The Selection can be a single cell or contiguous or noncontiguous (union) range of cells, while the SelectedCell is always a single cell inside the current selection. If a cell you assign to SelectedCell is outside the currently selected range, the selection will be changed - it will coincide with the specified active cell.

You can also select multiple non-adjacent cells or cell ranges in the worksheet simultaneously. To get or set the list of ranges selected in the active worksheet, use the GetSelectedRanges or SpreadsheetControl.SetSelectedRanges method, respectively. If there is more than one selected range in the worksheet (A2:C4, C6:C9, E3:F7, in the image below), the Selection property returns a complex (union) range that includes all the selected areas. You can access an individual range in the selection by its index in the CellRange.Areas collection.

SpreadsheetControl_Worksheet_MultipleSelectedRanges

To specify whether multi-selection is available to end-users in the SpreadsheetControl, use the SpreadsheetSelectionOptions.AllowMultiSelection option accessible via the SpreadsheetControl.Options.Behavior.Selection.AllowMultiSelection notation.

Note

To specify the cell selection and active cell in a specific worksheet of the document loaded in the SpreadsheetControl, use the Worksheet.Selection, Worksheet.SelectedCell, Worksheet.SetSelectedRanges and Worksheet.GetSelectedRanges members of the corresponding worksheet object.

See Also