Demonstrates the conditional column formatting.
Conditional formatting changes the default formatting of column cells, when a certain condition is met. NOV Grid for .NET provides strong support for authoring complex cell conditions.
Besides static fill rules, NOV Grid for .NET also supports gradient background and text fill declarations, that can be defined as a two color or three color gradient.
In this example Price background uses a two-color gradient background fill. The Product Name is has different background fill and font style applied to certain products (Aptax,Joykix,Zun Zimtam and Dingtincof).

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Data;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Grid;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NColumnsConditionalFormattingExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
// create a view and get its grid
NTableGridView view = new NTableGridView();
NTableGrid grid = view.Grid;
// bind the grid to the PersonsOrders data source
grid.DataSource = NDummyDataSource.CreatePersonsOrdersDataSource();
// Formatting Rule 1 = applied to the Product Name column.
// make the Aptax, Joykix, Zun Zimtam, Dingtincof cell backgrounds LightCoral, with a bold Font
{
// create the formatting rule and add it in the "Product Name" column
NColumn column = grid.Columns.GetColumnByFieldName("Product Name");
NFormattingRule formattingRule = new NFormattingRule();
column.FormattingRules.Add(formattingRule);
// row condition
NOrGroupRowCondition orCondition = new NOrGroupRowCondition();
orCondition.Add(new NOperatorRowCondition(new NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Aptax"));
orCondition.Add(new NOperatorRowCondition(new NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Joykix"));
orCondition.Add(new NOperatorRowCondition(new NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Zun Zimtam"));
orCondition.Add(new NOperatorRowCondition(new NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Dingtincof"));
formattingRule.RowCondition = orCondition;
// LightCoral background fill declaration
NBackgroundFillDeclaration backgroundFillDeclaration = new NBackgroundFillDeclaration();
backgroundFillDeclaration.Mode = ENFillDeclarationMode.Uniform;
backgroundFillDeclaration.UniformFill = new NColorFill(NColor.LightCoral);
formattingRule.Declarations.Add(backgroundFillDeclaration);
// Bold font style declaration
NFontStyleDeclaration fontStyleDeclaration = new NFontStyleDeclaration();
fontStyleDeclaration.FontStyle = ENFontStyle.Bold;
formattingRule.Declarations.Add(fontStyleDeclaration);
}
// Formatting Rule 2 = applied to the Product Name column.
// make the Aptax and Joykix cell backgrounds LightCoral, with a bold Font
{
// create the formatting rule and add it in the "Product Name" column
NColumn column = grid.Columns.GetColumnByFieldName("Price");
NFormattingRule formattingRule = new NFormattingRule();
column.FormattingRules.Add(formattingRule);
// row condition
formattingRule.RowCondition = new NTrueRowCondition();
// get price field min and max
object minPrice, maxPrice;
int priceFieldIndex = grid.DataSource.GetFieldIndex("Price");
grid.DataSource.TryGetMin(priceFieldIndex, out minPrice);
grid.DataSource.TryGetMax(priceFieldIndex, out maxPrice);
// make a graident fill declaration
NBackgroundFillDeclaration backgroundFillDeclaration = new NBackgroundFillDeclaration();
backgroundFillDeclaration.Mode = ENFillDeclarationMode.TwoColorGradient;
backgroundFillDeclaration.MinimumValue = Convert.ToDouble(minPrice);
backgroundFillDeclaration.MaximumValue = Convert.ToDouble(maxPrice);
backgroundFillDeclaration.BeginColor = NColor.Green;
backgroundFillDeclaration.EndColor = NColor.Red;
formattingRule.Declarations.Add(backgroundFillDeclaration);
}
return view;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return @"
Demonstrates the conditional column formatting.
Conditional formatting changes the default formatting of column cells, when a certain condition is met.
NOV Grid for .NET provides strong support for authoring complex cell conditions.
Besides static fill rules, NOV Grid for .NET also supports gradient background and text fill declarations,
that can be defined as a two color or three color gradient.
In this example Price background uses a two-color gradient background fill.
The Product Name is has different background fill and font style applied to certain products (Aptax,Joykix,Zun Zimtam and Dingtincof).
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Grid Column Conditional Formatting", "https://www.nevron.com/docs/openvision/grid-column-conditional-formatting.html"),
("Grid Row Conditions", "https://www.nevron.com/docs/openvision/grid-row-conditions.html"),
("Grid Column Formats", "https://www.nevron.com/docs/openvision/grid-column-formats.html"),
("Grid Row Values", "https://www.nevron.com/docs/openvision/grid-row-values.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
#endregion
#region Fields
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Grid
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Imports System
Public Class Form1
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Text = "NOV WinForms - NColumnsConditionalFormattingExample"
' Create the NOV example and its controls
Dim exampleContent As NWidget = CreateExampleContent()
Dim exampleControls As NWidget = CreateExampleControls()
If Not exampleControls Is Nothing Then
exampleControls.PreferredWidth = 300
End If
' Place the example and its controls in a pair box
Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
pairBox.FillMode = ENStackFillMode.First
pairBox.FitMode = ENStackFitMode.First
pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)
' Host the example in the form
Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
host.Dock = DockStyle.Fill
Controls.Add(host)
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
' create a view and get its grid
Dim view As NTableGridView = New NTableGridView()
Dim grid = view.Grid
' bind the grid to the PersonsOrders data source
grid.DataSource = NDummyDataSource.CreatePersonsOrdersDataSource()
' Formatting Rule 1 = applied to the Product Name column.
' make the Aptax, Joykix, Zun Zimtam, Dingtincof cell backgrounds LightCoral, with a bold Font
If True Then
' create the formatting rule and add it in the "Product Name" column
Dim column As NColumn = grid.Columns.GetColumnByFieldName("Product Name")
Dim formattingRule As NFormattingRule = New NFormattingRule()
column.FormattingRules.Add(formattingRule)
' row condition
Dim orCondition As NOrGroupRowCondition = New NOrGroupRowCondition()
orCondition.Add(New NOperatorRowCondition(New NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Aptax"))
orCondition.Add(New NOperatorRowCondition(New NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Joykix"))
orCondition.Add(New NOperatorRowCondition(New NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Zun Zimtam"))
orCondition.Add(New NOperatorRowCondition(New NFieldRowValue("Product Name"), ENRowConditionOperator.Equals, "Dingtincof"))
formattingRule.RowCondition = orCondition
' LightCoral background fill declaration
Dim backgroundFillDeclaration As NBackgroundFillDeclaration = New NBackgroundFillDeclaration()
backgroundFillDeclaration.Mode = ENFillDeclarationMode.Uniform
backgroundFillDeclaration.UniformFill = New NColorFill(NColor.LightCoral)
formattingRule.Declarations.Add(backgroundFillDeclaration)
' Bold font style declaration
Dim fontStyleDeclaration As NFontStyleDeclaration = New NFontStyleDeclaration()
fontStyleDeclaration.FontStyle = ENFontStyle.Bold
formattingRule.Declarations.Add(fontStyleDeclaration)
End If
' Formatting Rule 2 = applied to the Product Name column.
' make the Aptax and Joykix cell backgrounds LightCoral, with a bold Font
If True Then
' create the formatting rule and add it in the "Product Name" column
Dim column As NColumn = grid.Columns.GetColumnByFieldName("Price")
Dim formattingRule As NFormattingRule = New NFormattingRule()
column.FormattingRules.Add(formattingRule)
' row condition
formattingRule.RowCondition = New NTrueRowCondition()
' get price field min and max
Dim minPrice, maxPrice As Object
Dim priceFieldIndex = grid.DataSource.GetFieldIndex("Price")
grid.DataSource.TryGetMin(priceFieldIndex, minPrice)
grid.DataSource.TryGetMax(priceFieldIndex, maxPrice)
' make a graident fill declaration
Dim backgroundFillDeclaration As NBackgroundFillDeclaration = New NBackgroundFillDeclaration()
backgroundFillDeclaration.Mode = ENFillDeclarationMode.TwoColorGradient
backgroundFillDeclaration.MinimumValue = Convert.ToDouble(minPrice)
backgroundFillDeclaration.MaximumValue = Convert.ToDouble(maxPrice)
backgroundFillDeclaration.BeginColor = NColor.Green
backgroundFillDeclaration.EndColor = NColor.Red
formattingRule.Declarations.Add(backgroundFillDeclaration)
End If
Return view
End Function
Public Function CreateExampleControls() As NWidget
Return Nothing
End Function
Public Function GetExampleDescription() As String
Return "
Demonstrates the conditional column formatting.
Conditional formatting changes the default formatting of column cells, when a certain condition is met.
NOV Grid for .NET provides strong support for authoring complex cell conditions.
Besides static fill rules, NOV Grid for .NET also supports gradient background and text fill declarations,
that can be defined as a two color or three color gradient.
In this example Price background uses a two-color gradient background fill.
The Product Name is has different background fill and font style applied to certain products (Aptax,Joykix,Zun Zimtam and Dingtincof).
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Grid Column Conditional Formatting", "https://www.nevron.com/docs/openvision/grid-column-conditional-formatting.html"), ("Grid Row Conditions", "https://www.nevron.com/docs/openvision/grid-row-conditions.html"), ("Grid Column Formats", "https://www.nevron.com/docs/openvision/grid-column-formats.html"), ("Grid Row Values", "https://www.nevron.com/docs/openvision/grid-row-values.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class