Back to Devexpress

Table.MergeCellsAsync(TableCellPosition, TableCellPosition, CancellationToken) Method

blazor-devexpress-dot-blazor-dot-richedit-dot-table-dot-mergecellsasync-x28-devexpress-dot-blazor-dot-richedit-dot-tablecellposition-devexpress-dot-blazor-dot-richedit-dot-tablecellposition-system-dot-threading-dot-cancellationtoken-x29.md

latest3.6 KB
Original Source

Table.MergeCellsAsync(TableCellPosition, TableCellPosition, CancellationToken) Method

Merges all cells in the specified range.

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
public ValueTask MergeCellsAsync(
    TableCellPosition startPosition,
    TableCellPosition endPosition,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

NameTypeDescription
startPositionTableCellPosition

The position of the first cell in the range.

| | endPosition | TableCellPosition |

The position of the last cell in the range.

|

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 TableCellPosition object stores a cell’s position in a table. Pass two cell positions to the MergeCellsAsync method to merge all cells in the specified range. The result cell has the same appearance settings as the first cell in the range.

Note

The MergeCellsAsync method throws an exception if the table does not contain a cell at the specified position.

The following example merges 6 cells:

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);
            var startPosition = new TableCellPosition(0, 0); // The first cell in the first row
            var endPosition = new TableCellPosition(2, 1); // The second cell in the third row
            await firstTable.MergeCellsAsync(startPosition, endPosition);
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}

Call the SplitAsync method to split a cell into multiple smaller cells.

See Also

Tables in Blazor Rich Text Editor

Table Class

Table Members

DevExpress.Blazor.RichEdit Namespace