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.
Controls for rptMain
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 |
Tip: Even if you do not want colors in your finished reports, using background colors on subreports can help in troubleshooting layout issues. |
Controls for rptSub
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 |
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
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 |
To write the code in C#
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 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 |
To write the code in C#
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; |