Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TableCells.InsertAsync(Int32, Boolean, CancellationToken) Method

Inserts a cell to the right or left of the specified cell.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

#Declaration

C#
public ValueTask<TableCell> InsertAsync(
    int baseCellIndex,
    bool toRight = false,
    CancellationToken cancellationToken = default(CancellationToken)
)

#Parameters

Name Type Description
baseCellIndex Int32

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

#Optional Parameters

Name Type Default Description
toRight Boolean False

true to insert a cell to the right of the specified cell; false to insert a cell to the left of the specified cell.

cancellationToken CancellationToken null

An object that propagates a cancellation notification.

#Returns

Type Description
ValueTask<TableCell>

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

#Remarks

A table consists of cells combined into rows. The Rows property stores all table rows. A row stores its cells in the Cells property. Call the InsertAsync/RemoveAsync method to add/remove a cell to/from the row. Perform this action for each table row to add or remove a table column.

Note

The newly created cell copies appearance settings from the cell whose index you passed as the baseCellIndex parameter.

The following example adds two columns 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 cell to the left of the first cell
                await row.Cells.InsertAsync(0);
                // Inserts a cell to the right of the last cell
                await row.Cells.InsertAsync(row.Cells.Count - 1, true); 
            }
            richEdit.DocumentAPI.EndUpdate();
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}
See Also