Skip to main content

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

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

Namespace: DevExpress.Xpf.Spreadsheet

Assembly: DevExpress.Xpf.Spreadsheet.v24.2.dll

NuGet Package: DevExpress.Wpf.Spreadsheet

Declaration

public bool SetSelectedRanges(
    IList<CellRange> ranges,
    bool expandToMergedCellsSize
)

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 expanded to include merged cells.

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"]);
spreadsheetControl1.SetSelectedRanges(mylist, true);

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

SetSelectedRange_true

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

SetSelectedRange_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