Skip to main content

Tables

  • 4 minutes to read

RichEdit controls provide support for complex tables, as well as nested ones. An end-user can insert tables, edit a table layout by splitting and merging cells, and insert rows and columns. Borders and shading can be applied individually for each cell in a table.

RichEdit provides a set of commands to work with tables. These commands can be created and executed standalone. Command bars, menus or Ribbon interface make them available to end-users, as illustrated in the following picture.

DXRichEdit_Tables

The command bar provides end users with the ability to set borders, border color and cell shading.

DXRichEdit_Table_Shading

#Table API

You can use Table API to add, delete or modify tables programmatically. Table in a document is represented by an object with the Table inteface. To get access to rows and cells, the TableRow and TableCell interfaces are implemented. Tables are arranged in a TableCollection collection, accessible via the SubDocument.Tables property.

To get access to table contents, use Range properties of cells, rows and a table. Once you've got a document range, you can operate with it using its own methods or via the Document or SubDocument methods.

#Commands

You can use various commands to handle tables in the document. Some commands are already represented as buttons in a default bar or Ribbon UI, while others could be attached to interface elements if required.

Table commands are listed below.

#Insert Table Elements

Command Description
InsertTableCommand Inserts a table at the selection.
InsertTableColumnToTheLeftCommand Inserts a column to the left of the leftmost column in a selection.
InsertTableColumnToTheRightCommand Inserts a column to the right of the rightmost column in a selection.
InsertTableRowAboveCommand Inserts a row in a table above the currently selected row.
InsertTableRowBelowCommand Insert a row in a table below the currently selected row.
TabKeyCommand Adds a new row if the selection is in the last column of the last row in a table.

#Delete Table Elements

Command Description
DeleteTableCommand Deletes a selected table.
DeleteTableColumnsCommand Deletes selected columns in a table.
DeleteTableRowsCommand Deletes selected rows in a table.

#Merge and Split

Command Description
MergeTableCellsCommand Merges selected cells.
SplitTableCommand Splits a table at a selected row.

#Invoke Dialog Windows

Command Description
ShowInsertTableCellsFormCommand Invokes the 'Insert Cells' form used to select from the options to insert a cell, a row or a column.
ShowDeleteTableCellsFormCommand Invokes the 'Delete Cells' form used to select from the options to delete a cell, a row or a column.
ShowSplitTableCellsFormCommand Invokes the 'Split Cells' form used to specify the number of columns and rows into which the cell should be split.

#Show/Hide Borders

Command Description
ToggleTableCellsAllBordersCommand Toggles all borders for selected cells on/off.
ToggleTableCellsBottomBorderCommand Toggles bottom borders for selected cells on/off.
ToggleTableCellsInsideBorderCommand Toggles all inner borders for selected cells on/off.
ToggleTableCellsInsideHorizontalBorderCommand Toggles inner horizontal borders for selected cells on/off.
ToggleTableCellsInsideVerticalBorderCommand Toggles inner vertical borders for selected cells on/off.
ToggleTableCellsLeftBorderCommand Toggles left borders for selected cells on/off.
ToggleTableCellsOutsideBorderCommand Toggles outer borders for selected cells on/off.
ToggleTableCellsRightBorderCommand Toggles right borders for selected cells on/off.
ToggleTableCellsTopBorderCommand Toggles top borders for selected cells on/off.

#Change Cell Alignment

Command Description
ToggleTableCellsBottomCenterAlignmentCommand Toggles bottom-center alignment for selected cells on/off.
ToggleTableCellsBottomLeftAlignmentCommand Toggles bottom-left alignment for selected cells on/off.
ToggleTableCellsBottomRightAlignmentCommand Toggles bottom-right alignment for selected cells on/off.
ToggleTableCellsMiddleCenterAlignmentCommand Toggles middle-center alignment for selected cells on/off.
ToggleTableCellsMiddleLeftAlignmentCommand Toggles middle-left alignment for selected cells on/off.
ToggleTableCellsMiddleRightAlignmentCommand Toggles middle-right alignment for selected cells on/off.
ToggleTableCellsTopCenterAlignmentCommand Toggles top-center alignment for selected cells on/off.
ToggleTableCellsTopLeftAlignmentCommand Toggles top-left alignment for selected cells on/off.
ToggleTableCellsTopRightAlignmentCommand Toggles top-right alignment for selected cells on/off.

#Miscellaneous

Command Description
SelectTableCommand Selects an entire table in which a caret is located.
ToggleShowTableGridLinesCommand Toggles displaying grid lines for a table with no borders applied - on/off.