Back to Devexpress

Document.Selections Property

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-document-a83345a7.md

latest4.6 KB
Original Source

Document.Selections Property

Retrieves 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
SelectionCollection Selections { get; }
vb
ReadOnly Property Selections As SelectionCollection

Property Value

TypeDescription
SelectionCollection

A SelectionCollection object that contains ranges selected in the document.

|

Remarks

The SelectionCollection contains all ranges selected in the document. To add an item to the collection, use the SelectionCollection.Add method.

Use the SelectionCollection.RemoveAt method to unselect previously selected range.

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

Example

The code sample below shows how to select a cell content:

View Example

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

static void SelectSingleRange(Document document) {
    document.LoadDocument("Documents//SelectionCollection.docx", DocumentFormat.Docx);
    int startPos = 80;
    int endPos = document.Tables[0].Rows[1].LastCell.ContentRange.Start.ToInt();
    DocumentRange myRange = document.CreateRange(startPos, endPos - startPos);
    document.Selections.Add(myRange);
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

Shared Sub SelectSingleRange(ByVal document As Document)
    document.LoadDocument("Documents//SelectionCollection.docx", DocumentFormat.Docx)
    Dim startPos As Integer = 80
    Dim endPos As Integer = document.Tables(0).Rows(1).LastCell.ContentRange.Start.ToInt()
    Dim myRange As DocumentRange = document.CreateRange(startPos, endPos - startPos)
    document.Selections.Add(myRange)
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Selections property.

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.

wpf-rich-text-editor-customize-context-menu/CS/WpfRichEditorMenuCustomization/MainWindow.xaml.cs#L27

csharp
{
    var selectedRanges = richTextEditor.Document.Selections;
    foreach (var range in selectedRanges)

wpf-rich-text-editor-customize-context-menu/VB/WpfRichEditorMenuCustomization/MainWindow.xaml.vb#L17

vb
Private Sub HighlightSelection_ItemClick(ByVal sender As Object, ByVal e As DevExpress.Xpf.Bars.ItemClickEventArgs)
    Dim selectedRanges = richTextEditor.Document.Selections
    For Each range In selectedRanges

See Also

Document Interface

Document Members

DevExpress.XtraRichEdit.API.Native Namespace