vcl-dxrichedit-dot-nativeapi-dot-idxrichedittablecollection-dot-add-x28-idxricheditdocumentposition-integer-integer-tdxricheditautofitbehaviortype-integer-x29.md
Inserts an empty table with the set number of rows and columns at the specified position in the parent document.
function Add(const APos: IdxRichEditDocumentPosition; ARowCount: Integer; AColumnCount: Integer; AAutoFitBehavior: TdxRichEditAutoFitBehaviorType = TdxRichEditAutoFitBehaviorType.AutoFitToContents; AFixedColumnWidths: Integer = MinInt): IdxRichEditTable;
| 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.
|
| Type | Description |
|---|---|
| IdxRichEditTable |
The created table.
|
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.
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;
_di_IdxRichEditDocument ADocument;
_di_IdxRichEditTable ATable;
// ...
ADocument = dxRichEditControl1->Document;
ADocument->BeginUpdate(); // Initiates the following batch change
try
{
ATable = ADocument->Tables->Add(ADocument->CaretPosition, 3, 3);
for(int i = 0; i < ATable->Rows->Count; i++)
for(int j = 0; j < ATable->Rows->Self[i]->Cells->Count; j++)
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
}
See Also
IdxRichEditTableCollection.Delete Procedure
IdxRichEditTableCollection.Remove Procedure
IdxRichEditTableCollection Interface