Back to Devexpress

SelectionCollection Class

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-163f454c.md

latest4.0 KB
Original Source

SelectionCollection Class

A collection of selections in the document.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
public class SelectionCollection :
    IEnumerable<DocumentRange>,
    IEnumerable
vb
Public Class SelectionCollection
    Implements IEnumerable(Of DocumentRange),
               IEnumerable

The following members return SelectionCollection objects:

Remarks

All ranges selected in the document are contained in this collection. To add an item to the collection, select a range with a keyboard or mouse, or use the SelectionCollection.Add method.

To toggle selection, that is to unselect a previously selected range, use the SelectionCollection.RemoveAt method.

To unselect an arbitrary range, use the SelectionCollection.Unselect method.

Example

The code sample below shows how to select multiple ranges:

View Example

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

static void SelectMultipleRanges(Document document) {
    document.LoadDocument("Documents//SelectionCollection.docx", DocumentFormat.Docx);
    DocumentRange range1 = document.CreateRange(80, 100);
    DocumentRange range2 = document.CreateRange(300, 100);
    int startPos3 = document.Tables[0].Rows[0].LastCell.ContentRange.Start.ToInt();
    DocumentRange range3 = document.CreateRange(startPos3, 100);
    DocumentRange range4 = document.CreateRange(720, 100);
    document.Selections.Add(new List<DocumentRange>() { range1, range2, range3, range4 });
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

Shared Sub SelectMultipleRanges(ByVal document As Document)
    document.LoadDocument("Documents//SelectionCollection.docx", DocumentFormat.Docx)
    Dim range1 As DocumentRange = document.CreateRange(80, 100)
    Dim range2 As DocumentRange = document.CreateRange(300, 100)
    Dim startPos3 As Integer = document.Tables(0).Rows(0).LastCell.ContentRange.Start.ToInt()
    Dim range3 As DocumentRange = document.CreateRange(startPos3, 100)
    Dim range4 As DocumentRange = document.CreateRange(720, 100)
    document.Selections.Add(New List(Of DocumentRange)() From {range1, range2, range3, range4})
End Sub

Implements

IEnumerable<DocumentRange>

IEnumerable

Inheritance

Object SelectionCollection

Extension Methods

GetAsFrozen()

See Also

SelectionCollection Members

DevExpress.XtraRichEdit.API.Native Namespace