ActiveReports 6 Online Help
Run Time Layouts
Show AllShow All
Hide AllHide All

ActiveReports objects and controls are completely accessible at run time. You can modify the properties of any of the report sections or controls to produce a dynamic report. The section Format event allows you to modify the properties of the section and its controls, including height, visibility, and other visual properties. The Format event is the only event in which you can modify the printable area of a section. Once this event has run, any changes to the section's height are not reflected in the report output. This walkthrough illustrates how to create a report layout at run time based on user input.

Note: Add controls dynamically in the ReportStart event. Otherwise, results may be unpredictable. For more information on events, see the Sequence of Events topic.

This walkthrough is split up into the following activities:

Tip: For basic steps like adding a report to a Visual Studio project and viewing a report, please see the Basic Data Bound Reports walkthrough.

To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\GrapeCity\ActiveReports 6\Data\NWIND.MDB (on a 64-bit Windows operating system, a copy is located in C:\Program Files (x86)\GrapeCity\ActiveReports 6\Data\NWIND.MDB).

When you have completed this walkthrough, you will have an application that looks similar to the following.

To add controls to the form

  1. Resize the Windows form so that it is large enough to accommodate a number of controls.
  2. From the Visual Studio toolbox, drag the following controls onto the form and set the properties as indicated.

Form controls

To generate a dataset for the form

  1. From the Project menu, select Add New Item.
  2. Select DataSet, rename the file NWINDDataSet.xsd and click the Add button.
  3. In the DataSet Designer that appears, click the Server Explorer link.
  4. In the Server Explorer, expand the node for your local copy of the Northwind database, then the Tables node, and drag the Products table onto the DataSet designer.
    Tip: If you do not see a copy of the Northwind database, click the Connect to Database icon and follow the prompts.
  5. In the design view of your Windows form, expand the Data section of the Visual Studio Toolbox and double-click DataSet to open the Add Dataset dialog.
  6. Under Typed dataset, select YourProjectName.NWINDDataSet and click OK to make the dataset available to your Windows form. nwindDataSet1 appears in the tray below the form.

To add code to create the report layout

  1. Right-click on rptRunTime and select View Code.
  2. Add code within the class declaration of the report to:
    • Create an array of fields
    • Create an option for whether to use groups
    • Set properties on the report sections
    • Add textboxes and labels to the report based on the array of fields
    • Handle exceptions

To write the code in Visual Basic.NET

To write the code in C#

To add code to fill the check list with fields and to launch the report

  1. Right-click the Windows Form and select View Code.
  2. Add code within the class declaration of the form to:
    • Fill the check list with fields
    • Launch the report

To write the code in Visual Basic.NET

To write the code in C#

Adding code to alternate colors in the detail section

  1. Double-click in the detail section of rptRunTime. This creates an event-handling method for rptRunTime's Detail_Format event.
  2. Add code to the handler to alternate colors for a green bar report effect.

To write the code in Visual Basic.NET

To write the code in C#

Adding code to the ReportStart event to call the report layout code

  1. Double-click in the gray area below rptRunTime to create an event-handling method for rptRunTime's ReportStart event.
  2. Add code to call the constructReport method.

To write the code in Visual Basic.NET

To write the code in C#

Adding code to the button's Click event to collect the selected values and launch the report

  1. Double-click btnGenRep to create an event-handling method for its Click event.
  2. Add code to the handler to collect the selected values and launch the report.

To write the code in Visual Basic.NET

To write the code in C#

Adding code to enable the button when fields are selected

To write the code in Visual Basic.NET

To write the code in C#

Adding code to the Form_Load event to call the fill check list code

  1. Double-click the title bar of the form. This creates an event-handling method for the Windows Form_Load event.
  2. Add code to the handler to call the fillCheckBox() method to populate clbFields with field values and to handle exceptions.

To write the code in Visual Basic.NET

To write the code in C#

See Also

Concepts