Back to Devexpress

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

vcl-dxrichedit-dot-nativeapi-dot-idxrichedittablecollection-dot-add-x28-idxricheditdocumentposition-integer-integer-tdxricheditautofitbehaviortype-integer-x29.md

latest3.9 KB
Original Source

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

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

Parameters

NameTypeDescription
APosIdxRichEditDocumentPosition

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

TypeDescription
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:

delphi
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;
cpp
_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

IdxRichEditTableCollection Members

dxRichEdit.NativeApi Unit