Nevron Open Vision Documentation
Column Conditional Formatting

About Conditional Formatting

Conditional formatting helps you format certain data cell views, according to specific rules. The conditional formatting capabilities of a column format, are exposed as a collection of NFormattingRule instances that are contained inside a NFormattingRuleCollection accessible from the NColumnFormat.FormattingRules property.

Each formatting rule is a couple that packs a Row Condition together with a collection formatting declarations. The formatting rules of a column are represented by instances of the NFormattingRule class and are contained inside a NFormattingRuleCollection, accessible from the FormattingRules property of the NColumn class.

The formatting declarations are applied to a certain data cell view, if the row condition matches the data cell row value. The following code example applies a red background to all data cell views for which the sales value is larger than 500:

Conditional Formatting Example
Copy Code
// create a dummy data table
NMemoryDataTable dataTable = new NMemoryDataTable(
    new NFieldInfo("Company", typeof(string)),
    new NFieldInfo("Sales", typeof(double))
dataTable.AddRow("Egestas Duis Ltd", 347);
dataTable.AddRow("Vel Turpis Aliquam LLC", 852);
dataTable.AddRow("Ullamcorper Velit Associates", 724);

// create grid view and get its grid
NTableGridView gridView = new NTableGridView();
NTableGrid grid = gridView.Grid;

// bind the grid to data
grid.DataSource = new NDataSource(dataTable);

// get the sales column and apply conditional formatting to it
NColumn salesColumn = grid.Columns.GetColumnByFieldName("Sales");

// create a new formatting rule and add it the rules collection
NFormattingRule formattingRule = new NFormattingRule();

// create a row condition that matches Sales Greater than 500
formattingRule.RowCondition = new NOperatorRowCondition(new NFieldRowValue("Sales"), ENRowConditionOperator.GreaterThan, "500");
// create a red background fill declaration
formattingRule.Declarations.Add(new NBackgroundFillDeclaration(new NColorFill(NColor.Red)));
Formatting Declarations Hierarchy

The formatting declarations are represented by classes that derive from the NFormattingDeclaration class. The following image illustrates the current formatting declarations hierarchy:

Currently there are two general types of formatting declarations - fill declarations (for text and background) and font style declarations (for font name, size and style).

Fill Formatting Declarations

The fill formatting declarations derive from the base NFillDeclaration class. Since all data cell views derive from the base NWidget class, the NTextFillDeclaration and NBackgroundFillDeclaration can effectively be applied to all types of columns.

The respective fillings applied (to the background of the data cell view widget or to the font fill) is determined by the Mode property, which takes values from the ENFillDeclarationMode enumeration:

Font Formatting Declarations

There are three types font formatting declarations, that can affect the text formatting of NTextCellView data cell view widgets:

Note that the formatting declarations will only have effect if applied to a column, whose column format generates NTextCellView widgets. See the Formats Table for an overview of the column formats that generate NTextCellView widgets.
See Also
Send Feedback