Master-Detail Report (Detail Report Bands)
This tutorial describes the steps needed to create a master-detail report with hierarchically linked data using the Detail Report band. For an alternative approach, refer to Master-Detail Report (Subreports).
To start with this tutorial, create a new report and bind it to a data source. For this tutorial, in the Report Wizard, select the table that will be used as the principal table in the master-detail relation.
The topic consists of the following sections.
- Provide a Report Data Source with a Master-Detail Relation
- Design a Master-Detail Report
- View the Result
Provide a Report Data Source with a Master-Detail Relation
This section of the tutorial describes how to provide an SQL data source with a master-detail relation. If you are using an Entity Framework data source that contains data members with master-detail relations between them, the existing relations will be used automatically. In this case, you can skip this section of the tutorial and proceed to the next section: Design a Master-Detail Report.
To add a master-detail relation to an SQL data source, do the following.
Add a detail table to the report data source. To do this, right-click the data source in the Report Explorer, and select Manage Queries... in the invoked context menu.
In the invoked Manage Queries dialog, click Add.
Then, in the invoked Data Source Wizard, click Run Query Builder....
Add the detail table to the query and click OK.
- Click Finish to exit the Data Source Wizard. Then, click OK to exit the Manage Queries dialog.
Next, specify the relation between the data source tables. To do this, right-click the data source in the Report Explorer, and select Manage Relations... in the invoked context menu.
In the invoked Master-Detail Relation Editor, click the plus button next to the master query to add a new relation. Specify a relation condition as shown in the following image and click OK to exit the dialog.
The Field List will be updated to reflect the added relation.
Design a Master-Detail Report
To create the layout of a master-detail report, do the following.
Allocate parts of a master report on the report's Detail band.
For the master report to be generated properly, the report's Data Member should be set to the master query. If you added the master query first, this property is set to the required value automatically. Otherwise, you should manually specify the data member (for instance, in the Properties Panel).
To add a detail report band, right-click anywhere on the report's surface, and in the invoked context menu, select Insert Detail Report. When the report's data source contains a data relationship, it is displayed in the context menu.
Then, drop the required data fields from the Field List onto the Detail Report band.
Note that you should drop items from the relation node (in this example it is the CategoriesProducts section) for the detail report to be generated correctly.
View the Result
The master-detail report is now ready. Switch to the Print Preview tab and view the result.