ActiveReports 6 Online Help
Script for Simple Reports
Show AllShow All
Hide AllHide All

ActiveReports allows you to use scripting to embed code in reports saved to the XML-based RPX file format. By embedding script in reports saved as RPX files, you can later load, run, and display reports directly in the viewer control without using the designer. This walkthrough illustrates how to include scripting in a simple report.

This walkthrough is split 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 a report that looks similar to the following.

To temporarily connect the report to a data source

  1. Add an ActiveReports 6 File (xml-based) to a Visual Studio project and rename it rptScript.
    Note: The following steps are just for convenience so that the fields list in the Report Explorer can be populated at design time.
  2. Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
  3. On the OLE DB tab, next to Connection String, click the Build button.
  4. In the Data Link Properties window that appears, select Microsoft Jet 4.0 OLE DB Provider and click the Next button.
  5. Click the ellipsis (...) button to browse to the Northwind database. Click Open once you have selected the appropriate access path.
  6. Click OK to close the window and fill in the Connection String field.
  7. In the Query field, enter the following SQL query.
    SQL Query
    Copy Code
    SELECT * FROM categories INNER JOIN products ON categories.categoryid = products.categoryid ORDER BY products.categoryid, products.productid
  8. Click OK to save the data source and return to the report design surface.

To add controls to the report

  1. Right-click on the design surface of the report and select Insert then Group Header/Footer to add group header and footer sections to your report.
  2. Increase the group header section's height so that you have room to work.
  3. In the Properties Window, make the following changes to the group header:
    • BackColor: LightBlue
    • CanShrink: True
    • DataField: CategoryID
    • GroupKeepTogether: All
    • KeepTogether: True
  4. Add the following controls to the GroupHeader section and set the properties as indicated.

    Group header controls

  5. In the Report Explorer, expand the Fields node, then the Bound node, and drag the following fields onto the detail section, setting the properties as indicated.

    Detail section fields

  6. Set the CanShrink property of the detail section to True.
  7. Select both of the text boxes in the detail section, right-click and select Format Border.
    • Select dark cyan in the color combo box
    • Select the solid line in the Line Styles pane
    • Click the bottom edge in the Preview pane
    • Click the OK button to add a solid cyan line to the bottom edge of the text boxes.
  8. Increase the group footer section's height so that you have room to work.
  9. Make the following changes to the group footer:
    • BackColor: PaleGreen
    • CanShrink: True
  10. Add the following controls to the GroupFooter section, setting the properties as indicated.

    Group footer controls

To add scripting to the report to supply data for the controls

  1. Click in the grey area below the report to select it, and in the Properties Window, change the ScriptLanguage property for the report to the scripting language you want to use. The default setting is C#.
  2. Click the Script tab located at the bottom edge of the report designer to access the scripting editor.

  3. Add the scripting code.

The following example shows what the scripting code looks like.

Warning: Do not access the Fields collection outside the DataInitialize and FetchData events. Accessing the Fields collection outside of these events is not supported, and has unpredictable results.

To write the script in Visual Basic.NET.

To write the script in C#.

To save the report to an XML-based RPX file

  1. From the Report menu, select Save Layout.
  2. In the Save dialog that appears, enter a name for the report, i.e. rptScript.rpx, and click the Save button.
See Also

Concepts