SpreadsheetControl.SetSelectedRanges(IList<CellRange>, Boolean) Method
Selects cell ranges in the worksheet and specifies whether the selection expands to fit merged cells.
public bool SetSelectedRanges( IList<CellRange> ranges, bool expandToMergedCellsSize )
Public Function SetSelectedRanges( ranges As IList(Of CellRange), expandToMergedCellsSize As Boolean ) As Boolean
A list of the CellRange objects.
true, to expand the selection to include merged cells; otherwise, false.
true, if cell ranges are selected successfully; otherwise false.
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.
If the expandToMergedCellsSize parameter in the SetSelectedRanges method is set to false, the selection does not expand, as shown below:
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 SpreadsheetControl.Selection property specifies the range of cells selected in the worksheet. The SpreadsheetControl.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.