Skip to main content

IdxRichEditTableCollection.Add(IdxRichEditDocumentPosition,Integer,Integer,TdxRichEditAutoFitBehaviorType,Integer) Method

Inserts an empty table with the set number of rows and columns at the specified position in the parent document.

Declaration

function Add(const APos: IdxRichEditDocumentPosition; ARowCount: Integer; AColumnCount: Integer; AAutoFitBehavior: TdxRichEditAutoFitBehaviorType = TdxRichEditAutoFitBehaviorType.AutoFitToContents; AFixedColumnWidths: Integer = MinInt): IdxRichEditTable;

Parameters

Name Type Description
APos IdxRichEditDocumentPosition

The target position in the parent document.

ARowCount Integer

The number of rows in the created table.

AColumnCount Integer

The number of columns in the created table.

AAutoFitBehavior TdxRichEditAutoFitBehaviorType

Optional. Specifies how cells fit content.

AFixedColumnWidths Integer

Optional. Allows you to specify the required explicit column width, in document measurement units.

Returns

Type Description
IdxRichEditTable

The created table.

Remarks

Call the Add function to create a new table in a document and add the table to the end of the collection. You can use the Self property to access all created tables by index.

Code Example: Insert a Table at the Caret Position

The following code example creates a table with three rows and three columns at the current caret position and populates all cells in the table:

var
  ADocument: IdxRichEditDocument;
  ATable: IdxRichEditTable;
  I, J: Integer;
begin
  ADocument := dxRichEditControl1.Document;
  ADocument.BeginUpdate;  // Initiates the following batch change
  try
    ATable := ADocument.Tables.Add(ADocument.CaretPosition, 3, 3);
    for I := 0 to ATable.Rows.Count - 1 do
      for J := 0 to ATable.Rows.Self[I].Cells.Count - 1 do
        ADocument.InsertText(ATable.Cell(I, J).Range.Start, 'Lorem ipsum dolor sit amet');
  finally
    ADocument.EndUpdate;  // Calls EndUpdate regardless of the batch operation's success
  end;
end;

VCL Rich Edit Control: A Table Example

See Also