Back to Devexpress

TableCollection.Create(DocumentPosition, Int32, Int32) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-tablecollection-dot-create-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-system-dot-int32-system-dot-int32-x29.md

latest9.2 KB
Original Source

TableCollection.Create(DocumentPosition, Int32, Int32) Method

Inserts a blank table with the specified number of rows and columns at the specified position.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
Table Create(
    DocumentPosition pos,
    int rowCount,
    int columnCount
)
vb
Function Create(
    pos As DocumentPosition,
    rowCount As Integer,
    columnCount As Integer
) As Table

Parameters

NameTypeDescription
posDocumentPosition

A position at which a table is inserted.

| | rowCount | Int32 |

A number of table rows.

| | columnCount | Int32 |

A number of table columns.

|

Returns

TypeDescription
Table

The created table.

|

Remarks

Right-to-Left Direction in Tables

The inserted table’s text direction depends on the RightToLeft property value of a paragraph where the table should be inserted. If the paragraph’s RightToLeft property is set to true, the table’s RightToLeft property is automatically set to true. The RightToLeft property of all cell paragraphs is also set to true.

Use the ReadOnlyParagraphCollection.Get(DocumentPosition) method to obtain the paragraph where the DocumentPosition is located.

Successive Tables

When you call the Create method to insert a new table right before of after the existing table, these tables are merged, and the Create method returns the resulting table. Successive tables with different directions are not merged.

Set the RichEditControlCompatibility.MergeSuccessiveTables property to false to keep successive tables with the same direction separate.

Example

The code sample below creates a table with three columns and four rows:

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

using (var wordProcessor = new RichEditDocumentServer())
{
    Document document = wordProcessor.Document;

    // Create a new table
    Table table = document.Tables.Create(document.Range.End, 2, 2);

    // Add new rows to the table
    table.Rows.InsertBefore(0);
    table.Rows.InsertAfter(0);

    // Add a new column to the table
    table.Rows[0].Cells.Append()
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

Using wordProcessor As New RichEditDocumentServer()
    Dim document As Document = wordProcessor.Document
    ' Create a new table
    Dim table As Table = document.Tables.Create(document.Range.End, 2, 2)

    ' Add new rows to the table
    table.Rows.InsertBefore(0)
    table.Rows.InsertAfter(0)

    ' Add a new column to the table
    table.Rows(0).Cells.Append()
End Using

The following code snippets (auto-collected from DevExpress Examples) contain references to the Create(DocumentPosition, Int32, Int32) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Table.cs#L52

csharp
#region #CreateFixedTable
Table table = document.Tables.Create(document.Range.Start, 3, 4);

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/TableActions.cs#L56

csharp
#region #CreateFixedTable
Table table = document.Tables.Create(document.Range.Start, 3, 3);

word-document-api-examples/CS/CodeExamples/TablesActions.cs#L82

csharp
// Insert a new table with three rows and columns at the document range's start position.
Table table = document.Tables.Create(document.Range.Start, 3, 3);

spreadsheet-document-api-use-worksheet-table-as-data-source/CS/SpreadsheetDocumentServerAsDataSourceExample/Form1.cs#L34

csharp
SnapDocument listHeader = list.ListHeader;
Table listHeaderTable = listHeader.Tables.Create(listHeader.Range.End, 1, 3);
TableCellCollection listHeaderCells = listHeaderTable.FirstRow.Cells;

winforms-richedit-tables-simple-example/CS/TablesSimpleExample/Form1.cs#L22

csharp
// Create a new table and specify its layout type
table = document.Tables.Create(document.Range.End, 2, 2);

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Table.vb#L46

vb
#Region "#CreateFixedTable"
            Dim table As DevExpress.XtraRichEdit.API.Native.Table = document.Tables.Create(document.Range.Start, 3, 4)
            table.TableAlignment = DevExpress.XtraRichEdit.API.Native.TableRowAlignment.Center

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/TableActions.vb#L47

vb
' #Region "#CreateFixedTable"
            Dim table As Table = document.Tables.Create(document.Range.Start, 3, 3)

word-document-api-examples/VB/CodeExamples/TablesActions.vb#L78

vb
' Insert a new table with three rows and columns at the document range's start position.
Dim table As DevExpress.XtraRichEdit.API.Native.Table = document.Tables.Create(document.Range.Start, 3, 3)
' Align the table.

spreadsheet-document-api-use-worksheet-table-as-data-source/VB/SpreadsheetDocumentServerAsDataSourceExample/Form1.vb#L34

vb
Dim listHeader As SnapDocument = list.ListHeader
Dim listHeaderTable As Table = listHeader.Tables.Create(listHeader.Range.End, 1, 3)
Dim listHeaderCells As TableCellCollection = listHeaderTable.FirstRow.Cells

winforms-richedit-tables-simple-example/VB/TablesSimpleExample/Form1.vb#L23

vb
' Create a new table and specify its layout type
table = document.Tables.Create(document.Range.End, 2, 2)
' Add new rows to the table

See Also

TableCollection Interface

TableCollection Members

DevExpress.XtraRichEdit.API.Native Namespace