Skip to main content
Row

Worksheet.SetSelectedRanges(IList<CellRange>) Method

Sets cell ranges selected in the worksheet.

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

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 Worksheet.Selection property specifies the range of cells selected in the worksheet. The Worksheet.SelectedCell property specifies a single cell where data is inserted when an end-user types (in other words, this is an active cell). 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 set or get a collection of ranges selected in the worksheet, use the SetSelectedRanges or Worksheet.GetSelectedRanges method. If there is more than one selected range in the worksheet (A2:C4, C6:C9, E3:F7, in the image below), the Worksheet.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

The Selection, SelectedCell, ActiveCell, SetSelectedRanges and GetSelectedRanges members of the SpreadsheetControl or SpreadsheetControl object allow you to manage cell selection in the worksheet that is currently active in the control.

See Also