Skip to main content
All docs
V24.2

TableRows.InsertAsync(Int32, Boolean, CancellationToken) Method

Inserts a row above or below the specified row.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

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

Parameters

Name Type Description
baseRowIndex Int32

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

Optional Parameters

Name Type Default Description
below Boolean False

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

Type Description
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:

<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