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:
- Connecting the parent report to an XML data source
- Adding controls to display the data
- Adding code to create a new instance of the subreport
- Adding code to pass a subset of the parent report's data to the subreport
![]() |
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
- Add two ActiveReports to a Visual Studio project, naming them rptMain and rptSub.
- Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
- In the tabs along the top of the dialog, select XML.
- 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).
- In the Recordset Pattern field, enter //CUSTOMER.
- Click OK to return to the report design surface.
- 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
- Set the Height property of the page header section to 0.3.
- Set the CanShrink property of the Detail section to True to eliminate white space.
- Drag the following controls from the ActiveReports Toolbox onto the indicated section of rptMain, setting the properties as indicated.
| Control | Section | Text | DataField | Miscellaneous | Location | Size |
|---|---|---|---|---|---|---|
| Label | PageHeader | Orders by Customer | Font size = 14 Alignment = Center |
0, 0 in | 6.5, 0.25 in | |
| Label | Detail | Customer Name: | Bold | 0, 0 in | 1.2, 0.198 in | |
| TextBox | Detail | NAME | 1.2, 0 in | 2, 0.198 in | ||
| Label | Detail | Orders: | Bold | 1.2, 0.25 in | 1, 0.198 in | |
| Subreport | Detail | 2.3, 0.25 in | 4, 1 in |
To add controls to rptSub to display data
- Set the CanShrink property of the Detail section of rptSub to True to eliminate white space.
- 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. - Right-click the PageHeader or PageFooter section and select Delete. Subreports do not render these sections, so deleting them saves processing time.
- Add the following controls to the Detail section of rptSub, setting the properties as indicated:
| Control | DataField | Name | Miscellaneous | Location | Size |
|---|---|---|---|---|---|
| TextBox | TITLE | txtTitle | 0, 0 in | 2.9, 0.198 in | |
| TextBox | PRICE | txtPrice | Alignment = Right OutputFormat = $#,##0.00 (or select Currency in the dialog) |
3, 0 in | 1, 0.198 in |
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
- Right-click the design surface of rptMain and select View Code.
- At the top left of the code view of the report, click the drop-down arrow and select (rptMain Events).
- At the top right of the code window, click the drop-down arrow and select ReportStart. This creates an event-handling method for the ReportStart event.
- Add code to the handler to create an instance of rptSub.
The following example shows what the code for the method looks like.
| Visual Basic.NET code. Paste JUST ABOVE the ReportStart event. | Copy Code |
|---|---|
| Dim rpt As rptSub | |
| Visual Basic.NET code. Paste INSIDE the ReportStart event. | Copy Code |
|---|---|
| rpt = New rptSub | |
- Click in the gray area below rptMain to select it.
- Click the events icon in the Properties Window to display available events for the report.
- Double-click ReportStart. This creates an event-handling method for the report's ReportStart event.
- Add code to the handler to create a new instance of rptSub.
The following example shows what the code for the method looks like.
| C# code. Paste JUST ABOVE the ReportStart event. | Copy Code |
|---|---|
| private rptSub rpt; | |
| C# code. Paste INSIDE the ReportStart event. | Copy Code |
|---|---|
| rpt = new rptSub(); | |
To add code to pass a subset of the parent report's data to the subreport
- Double-click in the detail section of the design surface of rptMain to create a detail_Format event.
- 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
The following example shows what the code for the method looks like.
| Visual Basic.NET code. Paste INSIDE the Format event. | Copy Code |
|---|---|
Dim xmlDS As New DataDynamics.ActiveReports.DataSources.XMLDataSource
xmlDS.NodeList = CType(CType(Me.DataSource, DataDynamics.ActiveReports.DataSources.XMLDataSource).Field("ORDER/ITEM", True), System.Xml.XmlNodeList)
rpt.DataSource = xmlDS
Me.SubReport1.Report = rpt
| |
The following example shows what the code for the method looks like.
| C# code. Paste INSIDE the Format event. | Copy Code |
|---|---|
DataDynamics.ActiveReports.DataSources.XMLDataSource xmlDS = new DataDynamics.ActiveReports.DataSources.XMLDataSource();
xmlDS.NodeList = (System.Xml.XmlNodeList)((DataDynamics.ActiveReports.DataSources.XMLDataSource) this.DataSource).Field("ORDER/ITEM", true);
rpt.DataSource = xmlDS;
this.SubReport1.Report = rpt;
| |
Concepts
Subreports
Hide All