Version

About Conditional Formatting

Conditional formatting allows you to test certain values, such as a column of cells in WinGrid™, and apply specific appearances to any of those cells that match certain criteria. For instance, you can build a condition that will check if cell values are below a certain number (such as zero) and apply an Appearance object that sets the ForeColor of those cells to red.

Types of Conditions

There are several types of conditions that you can build. Some of these conditions use simple operators like LessThan or GreaterThan. Other conditions allow you to build complex formulas to meet your application’s individual needs. There are a total of four conditions that each implement the ICondition interface. These conditions are defined below.

  • Operator Condition — The OperatorCondition class gives you a simple way to perform common comparisons between two values. Using the ConditionOperator property, you can set the operator which defines how the two values will be compared. The CompareValue property represents the value that you will be testing a WinGrid cell against.

  • Formula Condition — The FormulaCondition class gives you much more flexibility than the OperatorCondition class does. Building a formula condition allows you to use our WinCalcManager™ component to build almost any formula imaginable. You can either set the Formula property with a formula string at run time or use the Formula Builder dialog box at design time.

  • True Condition — The TrueCondition class doesn’t really evaluate values with an operator or formula; it just returns True all the time. This is useful if you always want to apply default appearances for WinGrid cells that did not previously match other conditions.

  • Condition Group — The ConditionGroup class isn’t an evaluator as well. A condition group is a collection of conditions. You can add as many conditions as you want to a condition group. You control whether or not you want the associated appearance to be applied if every condition in the group is matched, or just one of them.

Mapping Conditions to Appearances

Once your conditions are built, you need to associate them with appearances. Building conditions and condition groups and matching them with appearances is all done at the same time during design time. You can learn more about building conditions at design time by reading Using the Conditional Formatting Dialog Box. The ConditionValueAppearance class performs this mapping; it is a collection of condition/appearance mappings. By using the Add method, you pass in the condition along with the appearance you want to associate with it. Once you have your collection (although only one condition/appearance mapping is necessary) of mapped conditions and appearances, set the ValueBasedAppearance property of a WinGrid column to the ConditionValueAppearance to finish up. That WinGrid column will now apply the appearances to any conditions that are matched.