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:
When you complete this walkthrough you get a layout that looks similar to the following at design time and at runtime.
To add an ActiveReport to the Visual Studio project
See Adding an ActiveReport to a Project for information on adding different report layouts.
To connect the Parent Report (rptMain) to a data source
//CUSTOMER.
To create a layout for the Parent Report (rptMain)
Property Name | Property Value |
---|---|
Text | Orders by Customer |
Location | 0, 0 in |
Size | 6.5, 0.25 in |
Font | Arial, 14pt, style=Bold |
Alignment | Center |
TextBox1
Property Name | Property Value |
---|---|
DataField | NAME |
Location | 1.2, 0 in |
Size | 2, 0.2 in |
Label1
Property Name | Property Value |
---|---|
Text | Customer Name: |
Location | 0, 0 in |
Size | 1.2, 0.2 in |
Font Bold | True |
Label2
Property Name | Property Value |
---|---|
Text | Orders: |
Location | 1.2, 0.25 in |
Size | 1, 0.2 in |
Font Bold | True |
Subreport
Property Name | Property Value |
---|---|
Location | 2.3, 0.25 in |
Size | 4, 1 in |
To create a layout for the Child Report (rptSub)
Property Name | Property Value |
---|---|
CanShrink | True |
BackColor | LightSteelBlue |
TextBox1
Property Name | Property Value |
---|---|
DataField | TITLE |
Name | txtTitle |
Location | 0, 0 in |
Size | 2.9, 0.2 in |
TextBox2
Property Name | Property Value |
---|---|
DataField | PRICE |
Name | txtPrice |
Location | 3, 0 in |
Size | 1, 0.2 in |
Alignment | Right |
OutputFormat | $#,##0.00 (or select Currency in the dialog) |
To add code to create a new instance of the Child Report (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 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 add code to pass a subset of the Parent Report's data to the Child Report
To add code to pass a subset of the parent report's data 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 GrapeCity.ActiveReports.Data.XMLDataSource xmlDS.NodeList = CType(CType(Me.DataSource, GrapeCity.ActiveReports.Data.XMLDataSource).Field("ORDER/ITEM", True), System.Xml.XmlNodeList) rpt.DataSource = xmlDS 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
|
---|---|
GrapeCity.ActiveReports.Data.XMLDataSource xmlDS = new GrapeCity.ActiveReports.Data.XMLDataSource(); xmlDS.NodeList = (System.Xml.XmlNodeList)((GrapeCity.ActiveReports.Data.XMLDataSource) this.DataSource).Field("ORDER/ITEM", true); rpt.DataSource = xmlDS; subReport1.Report = rpt; |
To view the report
OR