Skip to main content

SelectionCollection.Add(List<DocumentRange>) Method

Adds listed ranges to the collection of selections.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v24.1.Core.dll

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

Declaration

public void Add(
    List<DocumentRange> items
)

Parameters

Name Type Description
items List<DocumentRange>

A List<T><DocumentRange,> list of document ranges.

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 specified ranges.

The following code snippet illustrates that ranges may merge in the collection. Three ranges form only one collection item.

View Example

document.LoadDocument("SelectionCollection.docx", DocumentFormat.OpenXml)
Dim range1 As DocumentRange = document.CreateRange(document.Range.Start, 12)
Dim range2 As DocumentRange = document.CreateRange(document.Range.Start.ToInt() + 12, 9)
Dim range3 As DocumentRange = document.CreateRange(document.Range.Start.ToInt() + 21, 3)

Dim ranges As New List(Of DocumentRange)() From {range1, range2}
document.Selections.Add(ranges)

Dim comment As Comment = document.Comments.Create(document.Selection, "")
Dim commentDoc As SubDocument = comment.BeginUpdate()
commentDoc.AppendText(String.Format(ControlChars.CrLf & "SelectionCollection " & ControlChars.CrLf & "contains {0} item(s).", document.Selections.Count))
comment.EndUpdate(commentDoc)

This snippet shows that a range can be split into several items in the SelectionCollection. A single range results in four items in the selection collection.

View Example

document.LoadDocument("SelectionCollection.docx", DocumentFormat.OpenXml)
Dim rootTable As Table = document.Tables(0)
Dim position10 As DocumentPosition = rootTable.Rows(0).Cells(1).Range.Start
Dim position11 As DocumentPosition = rootTable.Rows(3).LastCell.Range.End

Dim range1 As DocumentRange = document.CreateRange(position10, position11.ToInt() - position10.ToInt())
document.Selections.Add(range1)

Dim comment As Comment = document.Comments.Create(document.Selection, "")
Dim commentDoc As SubDocument = comment.BeginUpdate()
commentDoc.AppendText(String.Format(ControlChars.CrLf & "SelectionCollection " & ControlChars.CrLf & "contains {0} item(s).", document.Selections.Count))
comment.EndUpdate(commentDoc)

Important

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

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