ActiveReports 6 Online Help
Subreports with XML Data
Show AllShow All
Hide AllHide All

Using XML data requires some setup that is different from other types of data. This walkthrough illustrates how to set up a subreport bound to the XML DataSource in the parent report.

This walkthrough is split up into the following activities:

Tip: For basic steps like viewing a report, please see the Basic Data Bound Reports walkthrough.

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

When you have finished this walkthrough, you will have a report that looks similar to the following.

To connect the parent report to a data source

  1. Add two ActiveReports to a Visual Studio project, naming them rptMain and rptSub.
  2. Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
  3. In the tabs along the top of the dialog, select XML.
  4. Click the ellipsis button beside File URL to browse for the access path to Customer.xml and click Open. (The default installation path is C:\Program Files\GrapeCity\ActiveReports 6\Data\customer.xml, or C:\Program Files (x86)\GrapeCity\ActiveReports 6\Data\customer.xml on a 64-bit Windows operating system).
  5. In the Recordset Pattern field, enter //CUSTOMER.
  6. Click OK to return to the report design surface.
  7. In the Report Explorer, expand the Fields node, then the Bound node, then Document, then Customer to see the fields.

To add controls to rptMain to display data

  1. Set the Height property of the page header section to 0.3.
  2. Set the CanShrink property of the Detail section to True to eliminate white space.
  3. Drag the following controls from the ActiveReports Toolbox onto the indicated section of rptMain, setting the properties as indicated. 

Controls for rptMain

To add controls to rptSub to display data

  1. Set the CanShrink property of the Detail section of rptSub to True to eliminate white space.
  2. Set the BackColor property of the Detail section to LightSteelBlue to distinguish the subreport from the main report.
    Tip: Even if you do not want colors in your finished reports, using background colors on subreports can help in troubleshooting layout issues.
  3. Right-click the PageHeader or PageFooter section and select Delete. Subreports do not render these sections, so deleting them saves processing time.
  4. Add the following controls to the Detail section of rptSub, setting the properties as indicated:

Controls for rptSub

To add code to create a new instance of the subreport

Warning: Do not create a new instance of the subreport in the Format event. Doing so creates a new subreport each time the section Format code is run, which uses a lot of memory.

To write the code in Visual Basic

To write the code in C#

To add code to pass a subset of the parent report's data to the subreport

  1. Double-click in the detail section of the design surface of rptMain to create a detail_Format event.
  2. Add code to the handler to:
    • Create a new DataDynamics XMLDataSource
    • Type cast the new data source as rptMain's data source and set the NodeList to the "ORDER/ITEM" field
    • Display rptSub in the subreport control
    • Pass the new data source to the subreport

To write the code in Visual Basic

To write the code in C#

See Also

Concepts

How To