Skip to main content

Selection(SubDocument, Int32) Constructor

Initializes a new instance of the Selection class and sets the caret position.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public Selection(
    SubDocument subDocument,
    int caretPosition
)

Parameters

Name Type Description
subDocument SubDocument

The sub-document that contains the caret.

caretPosition Int32

The caret position in the sub-document.

Remarks

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

<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, 8);
            @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}

The image below shows the result.

Rich Edit - Access selection in code

Handle the SelectionChanged event to react to changes in selection.

See Also