Reports for WinForms | ComponentOne
In This Topic
    Adding Alternating Background Color
    In This Topic

    To create a report with alternating background color, use the OnPrint property of the Detail section to change the BackColor property of the section. 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 the report from the drop-down list above the Properties window.
    5. Locate the OnOpen property and enter cnt = 0. This initializes the cnt variable.
    6. Next, select Detail from the drop-down list above the Properties window.
    7. Locate the OnPrint property and click the empty field next to it, and then click the ellipsis button.
    8. The VBScript Editor appears. Enter the following VBScript expression in the code editor:
      cnt = cnt + 1
      if cnt mod 2 = 0 then
        detail.backcolor = rgb(200,220,200)
      else
        detail.backcolor = rgb(255,255,255)
      endif
      
    9. Click the Preview button to preview the report with alternating background.

    This topic illustrates the following:

    This report illustrates the alternating background color.


    Whenever a Detail section is rendered, the counter is incremented and the BackColor property of the Detail section is toggled.

    Note: For the complete report, see report "01: Alternating Background (Greenbar report)" in the CommonTasks.xml report definition file, which is available in the ComponentOne Samples folder.