All docs
V20.2
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
Row

Worksheet.SetSelectedRanges(IList<CellRange>, Boolean) Method

Selects cell ranges in the worksheet and specifies whether the selection expands to fit merged cells.

Namespace: DevExpress.Spreadsheet

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

Declaration

bool SetSelectedRanges(
    IList<CellRange> ranges,
    bool expandToMergedCellsSize
)
Function SetSelectedRanges(
    ranges As IList(Of CellRange),
    expandToMergedCellsSize As Boolean
) As Boolean

Parameters

Name Type Description
ranges IList<CellRange>

A list of the CellRange objects.

expandToMergedCellsSize Boolean

true, to expand the selection to include merged cells; otherwise, false.

Returns

Type Description
Boolean

true, if cell ranges are selected successfully; otherwise false.

Remarks

To select multiple non-adjacent cells or cell ranges in the worksheet simultaneously, use the SetSelectedRanges method. The expandToMergedCellsSize parameter enables you to determine whether to create a selection including merged cells, as illustrated below.

Worksheet sheet = spreadsheetControl1.ActiveWorksheet;
sheet.MergeCells(sheet.Range["E5:F9"]);
List<CellRange> mylist = new List<CellRange>();
mylist.Add(sheet.Range["A2:C4"]);
mylist.Add(sheet.Range["C6:C9"]);
mylist.Add(sheet.Range["E3:E7"]);
sheet.SetSelectedRanges(mylist, true);

The code results in a selection that includes merged cells, as shown in the following picture.

setselection_true

If the expandToMergedCellsSize parameter in the SetSelectedRanges method is set to false, the selection does not expand, as shown below:

setselection_false

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.

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 the 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 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.

See Also