blazor-devexpress-dot-blazor-dot-richedit-dot-tablecells-dot-insertasync-x28-system-dot-int32-system-dot-boolean-system-dot-threading-dot-cancellationtoken-x29.md
Inserts a cell to the right or left of the specified cell.
Namespace : DevExpress.Blazor.RichEdit
Assembly : DevExpress.Blazor.RichEdit.v25.2.dll
NuGet Package : DevExpress.Blazor.RichEdit
public ValueTask<TableCell> InsertAsync(
int baseCellIndex,
bool toRight = false,
CancellationToken cancellationToken = default(CancellationToken)
)
| Name | Type | Description |
|---|---|---|
| baseCellIndex | Int32 |
The index of the cell relative to which to insert a cell.
|
| 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.
|
| Type | Description |
|---|---|
| ValueTask<TableCell> |
A structure that stores an awaitable result of an asynchronous operation. The awaitable result is a new cell.
|
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:
<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