Reports for WinForms | ComponentOne
In This Topic
    Adding Conditional Formatting
    In This Topic

    In some cases you may want to change a field's appearance depending on the data it represents. For example, you may want to highlight items that are expensive, or low in stock. This can be done with script.

    To do this, 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 drop-down list above the Properties window (since this section contains the fields to add conditional formatting to).
    5. Locate the OnFormat property and click the empty field next to it, and then click the ellipsis button.
    6. The VBScript Editor appears. Enter the following VBScript expression in the code editor:
      ' VBScript: Detail.OnFormat
      If UnitsInStock + UnitsOnOrder < ReorderLevel And _
         Discontinued = False Then
        Detail.BackColor = rgb(255,190,190)
      Else
        Detail.BackColor = vbWhite
      Endif
      

      The script changes the Detail section's BackColor property depending on the value of the fields UnitsInStock, UnitsOnOrder, ReorderLevel, and Discontinued.

    Note: For the complete report, see report "16: Conditional Formatting" in the CommonTasks.xml report definition file, which is available in the ComponentOne Samples folder.