Back to Devexpress

TableRows.RemoveAsync(Int32, CancellationToken) Method

blazor-devexpress-dot-blazor-dot-richedit-dot-tablerows-dot-removeasync-x28-system-dot-int32-system-dot-threading-dot-cancellationtoken-x29.md

latest3.5 KB
Original Source

TableRows.RemoveAsync(Int32, CancellationToken) Method

Removes a row with the specified index from the table.

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
public ValueTask RemoveAsync(
    int rowIndex,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

NameTypeDescription
rowIndexInt32

A row index in the collection.

|

Optional Parameters

NameTypeDefaultDescription
cancellationTokenCancellationTokennull

An object that propagates a cancellation notification.

|

Returns

TypeDescription
ValueTask

A structure that stores an awaitable result of an asynchronous operation.

|

Remarks

A table consists of cells combined into rows. Use the Rows property to access the table row collection. Call the InsertAsync/RemoveAsync method to add/remove a row to/from the table.

Note

Once you remove all rows from a table, the component removes the table from the document.

The following example removes the first row from a table:

razor
<DxRichEdit @ref="richEdit" />

@code {
    DxRichEdit richEdit;
    protected override async Task OnAfterRenderAsync(bool firstRender) {
        if (firstRender)
            try {
                await InitializeDocument();
            }
            catch (TaskCanceledException) { }
        await base.OnAfterRenderAsync(firstRender);
    }

    async Task InitializeDocument() {
    /* 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 {
            var columnCount = 4;
            var rowCount = 5;
            richEdit.DocumentAPI.BeginUpdate();
            Table firstTable = await richEdit.DocumentAPI.Tables.CreateAsync(0, columnCount, rowCount);
            for (int i = rowCount-1; i >=0 ; i--)
                for (int j = columnCount-1; j >=0 ; j--) {
                    var cellPosition = firstTable.Rows[i].Cells[j].Interval.Start;
                    await richEdit.DocumentAPI.AddTextAsync(cellPosition, "sample text");
                }
            await firstTable.Rows.RemoveAsync(0);
            richEdit.DocumentAPI.EndUpdate();
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}

See Also

Tables in Blazor Rich Text Editor

TableRows Class

TableRows Members

DevExpress.Blazor.RichEdit Namespace