Skip to main content
All docs
V19.1

SpreadsheetControl.SetSelectedRanges(IList<Range>) Method

Selects multiple ranges in the active worksheet.

Namespace: DevExpress.Xpf.Spreadsheet

Assembly: DevExpress.Xpf.Spreadsheet.v19.1.dll

Declaration

public bool SetSelectedRanges(
    IList<Range> ranges
)

Parameters

Name Type Description
ranges IList<Range>

A list of the Range 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 active worksheet, the method returns false.

Remarks

The image below illustrates the use of the SpreadsheetControl.SetSelectedRanges method to select multiple non-adjacent ranges. The SpreadsheetControl.SelectedCell sets the selected (active) cell that gets user input. Note that if a cell outside the selected ranges was assigned to the SelectedCell property, selected ranges would be reset so that the active cell becomes the only selected range in the worksheet.

SetSelectedRanges

static void SetSelectedRanges(SpreadsheetControl control)
{
    control.BeginUpdate();
    Worksheet worksheet = control.ActiveWorksheet;

    Range r1 = worksheet.Range["A1:B10"];
    Range r2 = worksheet.Range["E12"];
    Range r3 = worksheet.Range["D4:E7"];
    List<Range> rlist = new List<Range>() { r1, r2, r3 };
    control.SetSelectedRanges(rlist);

    control.SelectedCell = worksheet.Cells["E5"];

    control.EndUpdate();
}

End-users can select multiple ranges if the SpreadsheetSelectionOptions.AllowMultiSelection option is true. This option is accessible via the SpreadsheetControl.Options.Behavior.AllowMultiSelection notation.

Note

To select ranges in a specific worksheet (which may or may not be active) of the document loaded in the SpreadsheetControl, use the Worksheet.SetSelectedRanges method of the worksheet object.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetSelectedRanges(IList<Range>) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also