ActiveReports for .NET 3 Online Help Request technical support
Subreports with XML Data
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Advanced > Subreports Walkthroughs > Subreports with XML Data

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.

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).

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

Adding two ActiveReports to a Visual Studio project

To add two ActiveReports to a Visual Studio project

  1. Open a new project in Visual Studio.
  2. From the Project menu, select Add New Item.
  3. Select ActiveReports 3.0 File and rename the file rptMain.
  4. Click Open.
  5. From the Project menu, select Add New Item.
  6. Select ActiveReports 3.0 File and rename the file rptSub.
  7. Click Open.

Connecting the parent report to a data source

To connect the parent report to a data source

  1. Click on the gray report DataSource icon in the Detail section to open the report DataSource dialog.
  2. In the Data source combo box at the top of the dialog, select XML.
  3. Click the ellipsis button beside File URL to browse for the access path to Customer.xml. Click Open once you have selected the appropriate access path. (The default installation path is C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Samples\CSharp\XMLSample\customer.xml.)
  4. In the Recordset Pattern field, type "//CUSTOMER".
  5. Click OK to return to the report design surface.

Adding controls to display the data

To add controls to the reports

  1. Add the following controls to the Detail section of rptMain, naming them as indicated:

    Control DataField Name Text/ReportName Location
    Label lblCustomerName Customer Name:  0, 0 in
    TextBox NAME  txtCustomerName NAME 1.2, 0 in
    Label lblOrders Orders: 0.25, 0.25 in
    Subreport ctlSubreport rptSub 0.75, 0.5 in

  2. Add the following controls to the Detail section of rptSub, naming them as indicated:

    Control DataField Name Text Location
    TextBox TITLE txtTitle TITLE 0, 0 in
    TextBox PRICE txtPrice PRICE 3.5, 0 in

Adding the code to create a new data source

To write the code in Visual Basic or C#

The following example shows what the code for the method looks like.

'Visual Basic
Private Sub Detail1_Format(ByVal sender As Object, ByVal e As System.EventArgs) _
     Handles Detail.Format
    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)
    Me.ctlSubreport.Report = New rptSub
    Me.ctlSubreport.DataSource = xmlDS
End Sub
     
//C#
private void detail_Format(object sender, System.EventArgs eArgs)
{
   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);
   this.ctlSubreport.Report = new rptSub();
   this.ctlSubreport.DataSource = xmlDS;
}

Viewing the report

To view the report

  1. Add the ActiveReports viewer control to a Windows Form.
  2. Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports Windows Form Viewer for help.
You can quickly view your report at design time by clicking the Preview tab at the bottom of the designer.

See Also

©2009. All Rights Reserved.