This tutorial demonstrates how to create a master-detail report using the XRSubreport control. This approach is useful if your data source does not contain ADO.NET relationship or you prefer to store master and detail reports in different files. Another approach is described at Create a Master-Detail Report with Detail Report Bands.
To get started with this tutorial, open an existing reporting application or create a new application (the Add a Report to Your .NET Application section explains how to create a reporting application on different platforms).
Perform the actions below to create a master-detail report by using subreports.
Create a Master Report and Bind It to Data
Bind your report to the "Categories" table of the sample Northwind database (nwind.mdb file is shipped with XtraReports installation).
Drag the CategoryName and Description fields from the Field List window and drop them onto the report's Detail band.
Then, with the right mouse button, drop the Picture field too, and on the invoked menu, choose PictureBox.
You can also set its Sizing property to ZoomImage to improve performance.
In the invoked FilterString Editor, construct an expression where the CategoryID data field is compared to the CatID parameter. To access the parameter, click the icon on the right until it turns into a question mark.
Embed the Subreport
Switch back to the XtraReport1.cs, and drop the XRSubreport control from the DX.19.2: Report ControlsToolbox tab onto the Detail band.
If the required report is not listed in this property editor, rebuild your solution by clicking Rebuild Solution on the project's Build menu.
Next, bind the subreport's CatID parameter used as a filtering criterion to the master report's CategoryID data field, which will serve as a source of the parameter value. To do this, click the subreport's smart tag and select Edit Parameter Bindings in the invoked actions list.
This will invoke a Parameter Bindings Collection Editor. Click Add to add new binding. In the binding properties list, specify the data field to which you want to bind a subreport parameter and the name of the parameter that you want to bind.
To avoid printing blank space when the subreport's height exceeds the height of its content, set the XRSubreport.CanShrink property to true.
Your report is now ready to be generated. In Visual Studio, you can view the report by switching to the Preview tab.
To learn how to make the detail sections collapse or expand when clicking them in Print Preview, see Create Drill-Down Reports.