.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

SelectionCollection.Add(List<DocumentRange>) Method

Adds listed ranges to the collection of selections.

Namespace: DevExpress.XtraRichEdit.API.Native

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

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.

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.

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.

See Also