Skip to main content
A newer version of this page is available.
All docs
V19.1

How to: Create a Table with Fixed Column Width

To create a table with fixed column widths, specify the following settings as shown in the code sample below.

Table Element

Property

Value

Table

Table.TableLayout

Table.PreferredWidthType

TableLayoutType.Fixed

WidthType.Fixed

Cell

TableCell.PreferredWidthType

TableCell.PreferredWidth

WidthType.Fixed

A floating point value specifying the cell width. To avoid dimensional changes at runtime, convert this value to document units of measurement (determined by the Document.Unit property). To do that, use the corresponding Units class method.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/wpf-richedit-document-api-t213968.

Table table = document.Tables.Create(document.Range.Start, 3, 3);

table.TableAlignment = TableRowAlignment.Center;
table.TableLayout = TableLayoutType.Fixed;
table.PreferredWidthType = WidthType.Fixed;
table.PreferredWidth = DevExpress.Office.Utils.Units.InchesToDocumentsF(4f);

table.Rows[1].HeightType = HeightType.Exact;
table.Rows[1].Height = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.8f);

table[1, 1].PreferredWidthType = WidthType.Fixed;
table[1, 1].PreferredWidth = DevExpress.Office.Utils.Units.InchesToDocumentsF(1.5f);

The image below illustrates the result of the code execution.

APIExamples_Tables_FixedColumnWidth