officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-tableconditionalstyleproperties-dot-createconditionalstyle-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-conditionaltablestyleformattingtypes-x29.md
Creates a table style for the specified table elements and adds it to the collection.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
TableConditionalStyle CreateConditionalStyle(
ConditionalTableStyleFormattingTypes condition
)
Function CreateConditionalStyle(
condition As ConditionalTableStyleFormattingTypes
) As TableConditionalStyle
| Name | Type | Description |
|---|---|---|
| condition | ConditionalTableStyleFormattingTypes |
Indicates a table element to which a style can be applied.
|
| Type | Description |
|---|---|
| TableConditionalStyle |
An object that contains style properties.
|
After a conditional style is created, you can access it using the TableStyle.ConditionalStyleProperties property and index notation. The index is the ConditionalTableStyleFormattingTypes enumeration value.
Apply a table style using the Table.Style property. Subsequently, use the Table.TableLook property to selectively apply conditional styles.
The code sample below creates a new table style based on the Grid Table 5 Dark Accent 1 style, specifies style options for the first row, first column, odd and even banding columns, and applied the style to a table.
using DevExpress.XtraRichEdit.API.Native;
using System.Windows.Forms;
Document document = wordProcessor.Document;
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\TableStyles.docx", DocumentFormat.Docx);
// Access a document.
Document document = wordProcessor.Document;
// Start to edit the document.
document.BeginUpdate();
// Create a new table style.
TableStyle myNewStyle = document.TableStyles.CreateNew();
// Specify the parent style.
// The created style inherits from the 'Grid Table 5 Dark Accent 1' style
// defined in the loaded document.
myNewStyle.Parent = document.TableStyles["Grid Table 5 Dark Accent 1"];
// Create conditional styles for table elements.
TableConditionalStyle myNewStyleForFirstRow =
myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.FirstRow);
myNewStyleForFirstRow.CellBackgroundColor = Color.PaleVioletRed;
TableConditionalStyle myNewStyleForFirstColumn =
myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.FirstColumn);
myNewStyleForFirstColumn.CellBackgroundColor = Color.PaleVioletRed;
TableConditionalStyle myNewStyleForOddColumns =
myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.OddColumnBanding);
myNewStyleForOddColumns.CellBackgroundColor = ControlPaint.Light(Color.PaleVioletRed);
TableConditionalStyle myNewStyleForEvenColumns =
myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.EvenColumnBanding);
myNewStyleForEvenColumns.CellBackgroundColor = ControlPaint.LightLight(Color.PaleVioletRed);
document.TableStyles.Add(myNewStyle);
// Create a new table with four rows and columns
// at the document range's end position.
Table table = document.Tables.Create(document.Range.End, 4, 4, AutoFitBehaviorType.AutoFitToWindow);
// Apply the created style to the table.
table.Style = myNewStyle;
// Apply special formatting to the first row and first column.
table.TableLook = TableLookTypes.ApplyFirstRow | TableLookTypes.ApplyFirstColumn;
// Finalize to edit the document.
document.EndUpdate();
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Windows.Forms
Private document As Document = wordProcessor.Document
' Load a document from a file.
wordProcessor.LoadDocument("Documents\TableStyles.docx", DocumentFormat.Docx)
' Access a document.
Dim document As Document = wordProcessor.Document
' Start to edit the document.
document.BeginUpdate()
' Create a new table style.
Dim myNewStyle As TableStyle = document.TableStyles.CreateNew()
' Specify the parent style.
' The created style inherits from the 'Grid Table 5 Dark Accent 1' style
' defined in the loaded document.
myNewStyle.Parent = document.TableStyles("Grid Table 5 Dark Accent 1")
' Create conditional styles for table elements.
Dim myNewStyleForFirstRow As TableConditionalStyle =
myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.FirstRow)
myNewStyleForFirstRow.CellBackgroundColor = Color.PaleVioletRed
Dim myNewStyleForFirstColumn As TableConditionalStyle =
myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.FirstColumn)
myNewStyleForFirstColumn.CellBackgroundColor = Color.PaleVioletRed
Dim myNewStyleForOddColumns As TableConditionalStyle =
myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.OddColumnBanding)
myNewStyleForOddColumns.CellBackgroundColor =
ControlPaint.Light(Color.PaleVioletRed)
Dim myNewStyleForEvenColumns As TableConditionalStyle =
myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.EvenColumnBanding)
myNewStyleForEvenColumns.CellBackgroundColor =
ControlPaint.LightLight(Color.PaleVioletRed)
document.TableStyles.Add(myNewStyle)
' Create a new table with four rows and columns
' at the document range's end position.
Dim table As Table = document.Tables.Create(document.Range.End, 4, 4, AutoFitBehaviorType.AutoFitToWindow)
' Apply the created style to the table.
table.Style = myNewStyle
' Apply special formatting to the first row and first column.
table.TableLook =
TableLookTypes.ApplyFirstRow Or TableLookTypes.ApplyFirstColumn
' Finalize to edit the document.
document.EndUpdate()
The following code snippets (auto-collected from DevExpress Examples) contain references to the CreateConditionalStyle(ConditionalTableStyleFormattingTypes) 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#L157
TableConditionalStyle myNewStyleForFirstRow =
myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.FirstRow);
myNewStyleForFirstRow.CellBackgroundColor = Color.PaleVioletRed;
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/TableActions.cs#L125
TableConditionalStyle myNewStyleForFirstRow =
myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.FirstRow);
myNewStyleForFirstRow.CellBackgroundColor = Color.PaleVioletRed;
winforms-richedit-tables-simple-example/CS/TablesSimpleExample/Form1.cs#L217
// Create conditional styles (styles for specific table elements)
TableConditionalStyle myNewStyleForOddRows = tStyleMain.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.OddRowBanding);
myNewStyleForOddRows.CellBackgroundColor = Color.FromArgb(196, 220, 182);
word-document-api-table-examples/CS/Program.cs#L203
//Create conditional styles (styles for specific table elements)
TableConditionalStyle myNewStyleForOddRows = tStyleMain.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.OddRowBanding);
myNewStyleForOddRows.CellBackgroundColor = Color.FromArgb(196, 220, 182);
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Table.vb#L141
' Create conditional styles (styles for table elements)
Dim myNewStyleForFirstRow As DevExpress.XtraRichEdit.API.Native.TableConditionalStyle = myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(DevExpress.XtraRichEdit.API.Native.ConditionalTableStyleFormattingTypes.FirstRow)
myNewStyleForFirstRow.CellBackgroundColor = System.Drawing.Color.PaleVioletRed
wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/TableActions.vb#L113
' Create conditional styles (styles for table elements)
Dim myNewStyleForFirstRow As TableConditionalStyle = myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.FirstRow)
myNewStyleForFirstRow.CellBackgroundColor = Color.PaleVioletRed
word-document-api-examples/VB/CodeExamples/TablesActions.vb#L197
' Create conditional styles for table elements.
Dim myNewStyleForFirstRow As DevExpress.XtraRichEdit.API.Native.TableConditionalStyle = myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(DevExpress.XtraRichEdit.API.Native.ConditionalTableStyleFormattingTypes.FirstRow)
myNewStyleForFirstRow.CellBackgroundColor = System.Drawing.Color.PaleVioletRed
winforms-richedit-tables-simple-example/VB/TablesSimpleExample/Form1.vb#L178
' Create conditional styles (styles for specific table elements)
Dim myNewStyleForOddRows As TableConditionalStyle = tStyleMain.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.OddRowBanding)
myNewStyleForOddRows.CellBackgroundColor = Color.FromArgb(196, 220, 182)
word-document-api-table-examples/VB/Program.vb#L163
'Create conditional styles (styles for specific table elements)
Dim myNewStyleForOddRows As TableConditionalStyle = tStyleMain.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.OddRowBanding)
myNewStyleForOddRows.CellBackgroundColor = Color.FromArgb(196, 220, 182)
See Also
TableConditionalStyleProperties Interface