Skip to main content

SpreadsheetControl.SetSelectedRanges(IList<CellRange>) Method

Sets cell ranges selected in the active worksheet.

Namespace: DevExpress.XtraSpreadsheet

Assembly: DevExpress.XtraSpreadsheet.v23.2.dll

NuGet Package: DevExpress.Win.Spreadsheet

Declaration

public bool SetSelectedRanges(
    IList<CellRange> ranges
)

Parameters

Name Type Description
ranges IList<CellRange>

A list of the CellRange objects.

Returns

Type Description
Boolean

true if cell ranges are selected successfully; otherwise false. If you pass null (Nothing in Visual Basic), or an empty list, or a list that contains at least one cell range located in a worksheet other than the current worksheet, the method returns false.

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 the 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 set or get the list of ranges selected in the active worksheet, use the SetSelectedRanges or SpreadsheetControl.GetSelectedRanges 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

When you call the SetSelectedRanges method, an active cell is automatically set to the top left cell of the first range in the passed list.

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