wpf-devexpress-dot-xpf-dot-spreadsheet-dot-spreadsheetcontrol-dot-setselectedranges-x28-system-dot-collections-dot-generic-dot-ilist-devexpress-dot-spreadsheet-dot-cellrange-x29.md
Selects multiple ranges in the active worksheet.
Namespace : DevExpress.Xpf.Spreadsheet
Assembly : DevExpress.Xpf.Spreadsheet.v25.2.dll
NuGet Package : DevExpress.Wpf.Spreadsheet
public bool SetSelectedRanges(
IList<CellRange> ranges
)
Public Function SetSelectedRanges(
ranges As IList(Of CellRange)
) As Boolean
| Name | Type | Description |
|---|---|---|
| ranges | IList<CellRange> |
A list of the CellRange objects.
|
| 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.
|
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.
static void SetSelectedRanges(SpreadsheetControl control)
{
control.BeginUpdate();
Worksheet worksheet = control.ActiveWorksheet;
CellRange r1 = worksheet.Range["A1:B10"];
CellRange r2 = worksheet.Range["E12"];
CellRange r3 = worksheet.Range["D4:E7"];
List<CellRange> rlist = new List<CellRange>() { r1, r2, r3 };
control.SetSelectedRanges(rlist);
control.SelectedCell = worksheet.Cells["E5"];
control.EndUpdate();
}
Private Shared Sub SetSelectedRanges(ByVal control As SpreadsheetControl)
control.BeginUpdate()
Try
Dim worksheet As Worksheet = control.Document.Worksheets.ActiveWorksheet
Dim r1 As CellRange = worksheet.Range("A1:B10")
Dim r2 As CellRange = worksheet.Range("E12")
Dim r3 As CellRange = worksheet.Range("D4:E7")
Dim rlist As New List(Of CellRange)() From {r1, r2, r3}
control.SetSelectedRanges(rlist)
control.SelectedCell = worksheet.Cells("E5")
Finally
control.EndUpdate()
End Try
End Sub
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.
See Also