Skip to main content

SelectionCollection.Add(DocumentRange) Method

Adds a range to the collection of selections.

Namespace: DevExpress.XtraRichEdit.API.Native

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

NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation

Declaration

public void Add(
    DocumentRange range
)

Parameters

Name Type Description
range DocumentRange

A DocumentRange to add.

Remarks

When several ranges is added to the collection, they do not necessarily retain its origin. The resulting items contained in the collection can be formed by merging or splitting the specified ranges.

Important

If the added range intersects with any selection in the collection, an exception is thrown.

Example

The code sample below show how to select the table:

View Example

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

static void SelectTable(Document document) {
    document.LoadDocument("Documents//SelectionCollection.docx", DocumentFormat.OpenXml);
    int startPos = document.Tables[0].FirstRow.FirstCell.ContentRange.Start.ToInt();
    int endPos = document.Tables[0].LastRow.LastCell.ContentRange.End.ToInt() + 1;
    DocumentRange range1 = document.CreateRange(startPos, endPos - startPos);
    document.Selections.Add(range1);
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Add(DocumentRange) 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