Back to Devexpress

TableRows.InsertAsync(Int32, Boolean, CancellationToken) Method

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

latest4.1 KB
Original Source

TableRows.InsertAsync(Int32, Boolean, CancellationToken) Method

Inserts a row above or below the specified row.

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
public ValueTask<TableRow> InsertAsync(
    int baseRowIndex,
    bool below = false,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

NameTypeDescription
baseRowIndexInt32

The index of the row relative to which to insert a row.

|

Optional Parameters

NameTypeDefaultDescription
belowBooleanFalse

true to insert a row below the specified row; false to insert a row above the specified row.

| | cancellationToken | CancellationToken | null |

An object that propagates a cancellation notification.

|

Returns

TypeDescription
ValueTask<TableRow>

A structure that stores an awaitable result of an asynchronous operation. The awaitable result is a new row.

|

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

The newly created row copies appearance settings from the row whose index you passed as the baseRowIndex parameter.

The following example adds two rows to 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();
            // Creates a table
            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");
                }
            foreach (TableRow row in firstTable.Rows) {
                // Inserts a row above the first row
                await firstTable.Rows.InsertAsync(0, false);
                // Inserts a row below the last row
                await firstTable.Rows.InsertAsync(firstTable.Rows.Count - 1, true);
            }
            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