Back to Devexpress

Selection(SubDocument, Int32, Int32) Constructor

blazor-devexpress-dot-blazor-dot-richedit-dot-selection-dot-ctor-x28-devexpress-dot-blazor-dot-richedit-dot-subdocument-system-dot-int32-system-dot-int32-x29.md

latest2.3 KB
Original Source

Selection(SubDocument, Int32, Int32) Constructor

Initializes a new instance of the Selection class and selects the specified interval.

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
public Selection(
    SubDocument subDocument,
    int startPosition,
    int length
)

Parameters

NameTypeDescription
subDocumentSubDocument

The sub-document that contains the selection.

| | startPosition | Int32 |

A start position of the selected interval.

| | length | Int32 |

A length of the selected interval.

|

Remarks

Call this constructor to select an interval in Rich Text Editor. To access the editor’s selection in code, bind the Selection property with @bind-Selection attribute.

razor
<DxRichEdit @bind-Selection="@selection" @ref="@richEdit" />

@code {
    DxRichEdit richEdit;
    Selection selection;
    @* ... *@
    /* Surround the code that contains an asynchronous operation with a try-catch block to handle
    the OperationCanceledException. This exception is thrown when an asynchronous operation is canceled. */
        try {
        @* ... *@
            selection = new Selection(richEdit.DocumentAPI, 4, 23);
            @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}

The image below shows the result.

Handle the SelectionChanged event to react to changes in selection.

See Also

Selection Class

Selection Members

DevExpress.Blazor.RichEdit Namespace