method ConditionalFormats.Add (Expression as String, [Key as Variant])
Adds a new expression to the collection and returns a reference to the newly created object.

TypeDescription
Expression as String A formal expression that indicates the formula being used when the format is applied. Please check the Expression property that shows the syntax of the expression that may be used. For instance, the "%0 >= 10 and %1 > 67.23" means all cells in the first column with the value less or equal than 10, and all cells in the second column with a value greater than 67.23 
Key as Variant A string or long expression that indicates the key of the expression being added. If the Key parameter is missing, by default, the current index in the ConditionalFormats collection is used. 
ReturnDescription
ConditionalFormatA ConditionalFormat object that indicates the newly format being added.
The conditional formatting feature allows you to apply formats to a cell or range of cells, and have that formatting change depending on the value of the cell or the value of a formula. Use the Add method to format cells or items based on values. Use the Add method to add new ConditionalFormat objects to the ConditionalFormats collection. By default, the ConditionalFormats collection is empty. A ConditionalFormat object indicates a formula and a format to apply to cells or items. The ApplyTo property specifies whether the ConditionalFormat object is applied to items or to cells in the column. Use the Expression property to retrieve or set the formula. Use the Key property to retrieve the key of the object. Use the Refresh method to update the changes on the control's content.

The conditional format feature may change the cells and items as follows:

The following VB sample bolds all items when the sum between first two columns is greater than 0:

View1.ConditionalFormats.Add("%0+%1>0").Bold = True

The following VB sample bolds the cells in the second column ( 1 ), if the sum between second and third column ( 2 ) is less than the value in the first column ( 0 ):

With View1.ConditionalFormats.Add("%1+%2<%0")
    .ApplyTo = 1
    .Bold = True
End With

The following C++ sample bolds all items when the sum between first two columns is greater than 0:

COleVariant vtEmpty;
m_grid.GetConditionalFormats().Add( "%0+%1>0", vtEmpty ).SetBold( TRUE );

The following C++ sample bolds the cells in the second column ( 1 ), if the sum between second and third column ( 2 ) is less than the value in the first column ( 0 ):

COleVariant vtEmpty;
CConditionalFormat cf = m_grid.GetConditionalFormats().Add( "%1+%2<%0", vtEmpty );
cf.SetBold( TRUE );
cf.SetApplyTo( 1 );

The following VB.NET sample bolds all items when the sum between first two columns is greater than 0:

AxView1.ConditionalFormats.Add("%0+%1>0").Bold = True

The following VB.NET sample bolds the cells in the second column ( 1 ), if the sum between second and third column ( 2 ) is less than the value in the first column ( 0 ):

With AxView1.ConditionalFormats.Add("%1+%2<%0")
    .ApplyTo = 1
    .Bold = True
End With

The following C# sample bolds all items when the sum between first two columns is greater than 0:

axView1.ConditionalFormats.Add("%0+%1>0", null).Bold = true

The following C# sample bolds the cells in the second column ( 1 ), if the sum between second and third column ( 2 ) is less than the value in the first column ( 0 ):

EXCASCADETREELib.ConditionalFormat cf = axView1.ConditionalFormats.Add("%1+%2<%0",null);
cf.Bold = true;
cf.ApplyTo = (EXCASCADETREELib.FormatApplyToEnum)1;

The following VFP sample bolds all items when the sum between first two columns is greater than 0:

thisform.View1.ConditionalFormats.Add("%0+%1>0").Bold = .t.

The following VFP sample bolds the cells in the second column ( 1 ), if the sum between second and third column ( 2 ) is less than the value in the first column ( 0 ):

with thisform.View1.ConditionalFormats.Add("%1+%2<%0")
	.Bold = .t.
	.ApplyTo = 1
endwith