Glossary Item Box
ActiveReports allows reports to contain any number of child reports by using the Subreport control. Child reports, or subreports, are executed each time the parent section (i.e. the section in which the Subreport control is placed) is printed.
Note: Subreports will not render PageHeader/Footer sections, so you can delete them to save on processing time.
This walkthrough illustrates how to set up a subreport bound to an XML DataSource by setting the Subreport control's Report property to the child report and how to modify the subreport record source from the data in the parent report to retrieve the correct information.
This walkthrough is split up into the following activities:
To complete the walkthrough, you must have access to the XML Customer database (Customer.xml) included with this installation.
When you have finished this walkthrough, you will have a report that looks similar to the following.
To add two ActiveReports to a Visual Studio project
To connect rptMain to a data source
To add controls to the reports
Control | DataField | Name | Text/ReportName | Location |
---|---|---|---|---|
Label | (Empty string) | lblCustomerName | Customer Name: | 0, 0 in |
TextBox | NAME | txtCustomerName | NAME | 1.2, 0 in |
Label | (Empty string) | lblOrders | Orders: | 0.25, 0.25 in |
Subreport | (Empty string) | ctlSubreport | rptSub | 0.75, 0.5 in |
Control | DataField | Name | Text | Location |
---|---|---|---|---|
TextBox | TITLE | txtTitle | TITLE | 0, 0 in |
TextBox | PRICE | txtPrice | PRICE | 3.5, 0 in |
To write the code in Visual Basic
To write the code in C#
The following example shows what the code for the method looks like.
' Visual Basic Private Sub Detail_Format(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Detail.Format Dim rpt As New rptSub Me.SubReport.Report = rpt 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) CType(Me.SubReport.Report, rptSub).DataSource = xmlDS End Sub
//C# private void Detail_Format(object sender, System.EventArgs eArgs) { rptSub rpt = new rptSub(); this.SubReport.Report = rpt; 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); ((rptSub)this.SubReport.Report).DataSource = xmlDS; }
To view the report
Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.