Skip to main content

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

TableCell Class

A table cell.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

#Declaration

C#
public class TableCell :
    DocumentElementBase,
    ITableCellProperties

The following members return TableCell objects:

#Remarks

A Table consists of cells combined into rows. Use the Rows property to access table rows. A row implements the Cells property that allows you to access, add, remove, and split cells. Call a cell’s ChangePropertiesAsync method to customize cell appearance.

Read Tutorial: Tables Run Demo: Document API

The following example creates a table and customizes the appearance of cells in the first row:

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 = firstTable.Rows.Count - 1; i >= 0 ; i--)
                for (int j = firstTable.Rows[i].Cells.Count - 1; j >= 0 ; j--) {
                    var cellPosition = firstTable.Rows[i].Cells[j].Interval.Start;
                    await richEdit.DocumentAPI.AddTextAsync(cellPosition, "sample text");
            }
            // Customizes the table
            foreach (TableCell cell in firstTable.Rows[0].Cells)
                await cell.ChangePropertiesAsync(properties => {
                    properties.BackgroundColor = System.Drawing.Color.AliceBlue;
                    properties.Borders = new TableCellBorders(BorderLineStyle.Single, System.Drawing.Color.Blue, 25);
                    properties.CharacterProperties.FontName = "Arial";
                    properties.ContentHorizontalAlignment = HorizontalAlignment.Center;
                    properties.ContentVerticalAlignment = VerticalAlignment.Center;
                    properties.Margins.Bottom = 100;
                    properties.Width = new TableWidth(TableWidthType.Percent, 100);
                });
            richEdit.DocumentAPI.EndUpdate();
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}

#Inheritance

Object
DevExpress.Blazor.RichEdit.Internal.DocumentObject
See Also