Glossary Item Box

ActiveReports for .NET 2 Online Help Send feedback to Data Dynamics

Subreports with XML Data

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.

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. Click on Project > Add New Item.
  3. Select ActiveReports file and rename the file rptMain.
  4. Click Open.
  5. Click on Project > Add New Item.
  6. Select ActiveReports file and rename the file rptSub.
  7. Click Open. (Add in Visual Studio 2005.)

Connecting the parent report to a data source

To connect rptMain to a data source

  1. Click on the yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.
  2. In the Data source combo box at the top of the dialog, select XML.
  3. Click on the ellipsis 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 2.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 (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

  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

To write the code in C#

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 WinForm Viewer for help.

 

 


Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.