ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Reports for WinForms Task-Based Help > Reporting Task-Based Help > Formatting Reports > Editing the Field's Format Based on Value

Editing the Field's Format Based on Value

You can change a report field's format based on its value by specifying an expression for the Detail section's OnFormat property.

To specify an expression for the OnFormat property, complete the following steps:

1.   Open the C1ReportDesigner. For more information on how to access the C1ReportDesigner, see Accessing C1ReportDesigner from Visual Studio.

2.   Create a new report or open an existing report. Once you have the report in the C1ReportDesigner, you can modify the report properties.

3.   Click the Close Print Preview button to begin editing the report.

4.   In Design mode, select Detail from the Property window's drop-down list to view the available properties for the Detail section.

5.   Locate the OnFormat property and click the ellipsis button next to the property.

6.   The VBScript Editor appears where you can specify an expression.

The following expression changes the UnitsInStock field's ForeColor to red if the sum of the UnitsInStock value and the UnitsOnOrder value is less than the ReorderLevel value. There are several ways to write this expression.

Option 1:

UnitsInStockCtl.Forecolor = Iif(UnitsInStock + UnitsOnOrder < ReorderLevel, vbRed, vbBlack)

 

Option 2:

lowStock = UnitsInStock + UnitsOnOrder < ReorderLevel

UnitsInStockCtl.Forecolor = Iif(lowStock, vbRed, vbBlack)

 

Option 3:

If UnitsInStock + UnitsOnOrder < ReorderLevel Then

    UnitsInStockCtl.Forecolor = vbRed

Else

    UnitsInStockCtl.Forecolor = vbBlack

End If

 

Option 4:

color = Iif(UnitsInStock + UnitsOnOrder < ReorderLevel, vbred, vbblack)

UnitsInStockCtl.Forecolor = color

This topic illustrates the following:

Notice that the Outback Lager's UnitsInStock value is formatted in red since the sum of the UnitsInStock and UnitsOnOrder is less than the ReorderLevel.

 


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.