property ConditionalFormat.Expression as String
Indicates the expression being used in the conditional format.

TypeDescription
String A formal expression that indicates the formula being used in formatting. For instance, "%0+%1>%2", highlights the cells or the items, when the sum between first two columns is greater than the value in the third column
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. The Expression property specifies a formula that indicates the criteria to format the items or the columns. Use the ApplyTo property to specify when the items or the columns are  formatted. Use the Add method to specify the expression at adding time. The Expression property may include variables, constants, operators or ( ) parenthesis.  A variable is defined as %n, where n is the index of the column ( zero based ). For instance, the %0 indicates the first column, the %1, indicates the second column, and so on.  A constant is a float expression ( for instance, 23.45 ). Use the Valid property checks whether the expression is syntactically correct, and can be evaluated. If the expression contains a variable that is not known, 0 value is used instead. For instance, if your control has 2 columns, and the expression looks like "%2 +%1 ", the %2 does not exist, 0 is used instead. When the control contains two columns the known variables are %0 and %1. 

The expression may be a combination of variables, constants, strings, dates and operators.  A string is delimited by ", ` or ' characters, and inside they can have the starting character preceded by \ character, ie "\"This is a quote\"". A date is delimited by two # characters, ie #1/31/2001 10:00# means the January 31th, 2001, 10:00 AM.

The expression supports cell's identifiers as follows:

This property/method supports predefined constants and operators/functions as described here.

Usage examples:

  1. "1", highlights all cells or items. Use this form, when you need to highlight all cells or items in the column or control. 
  2. "%0 >= 0", highlights the cells or items, when the cells in the first column have the value greater or equal with zero
  3. "%0 = 1 and %1 = 0", highlights the cells or items, when the cells in the first column have the value equal with 0, and the cells in the second column have the value equal with 0 
  4. "%0+%1>%2", highlights the cells or the items, when the sum between first two columns is greater than the value in the third column
  5. "%0+%1 > %2+%3", highlights the cells or items, when the sum between first two columns is greater than the sum between third and forth column.
  6. "%0+%1 >= 0 and (%2+%3)/2 < %4-5", highlights the cells or the items, when the sum between first two columns is greater than 0 and the half of the sum between third and forth columns is less than fifth column minus 5.
  7. "%0 startwith 'A'" specifies the cells that starts with A
  8. "%0 endwith 'Bc'" specifies the cells that ends with Bc
  9. "%0 contains 'aBc'" specifies the cells that contains the aBc string
  10. "lower(%0) contains 'abc'" specifies the cells that contains the abc, AbC, ABC, and so on
  11. "upper(%0)'" retrieves the uppercase string
  12. "len(%0)>0'" specifies the not blanks cells
  13. "len %0 = 0'" specifies the blanks cells

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

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

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

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 VB.NET sample bolds all items when the sum between first two columns is greater than 0:

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

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

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

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

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