The previous article demonstrates how to extract data from the object set in ActiveReport for. net. This section describes how to use a subreport to display data in a master-slave table.
1. when you need to display data in a master-slave table, using subreports can provide great flexibility. Generally, the information of the master table is displayed in detail, if you want to display the master table at the top of each page, you can put it in PageHeader. Then, place the sub-table information in Detail, bind the control in the sub-Report to the data source directly, or extract data from the object set using the method mentioned in the previous article.
2. Use the subreport:
Create a report, and then you can see the SubReport control in the toolbox. Drag and Drop a control to the Detail section and use this control to load the SubReport.
Create a new report named SubReport1, write code in the main report, select the Detail part in the page designer, switch to the event bar in the Properties window, and double-click Format, the Detail_Format event is generated. The following describes the report to be loaded by the subreport control.
3. Because the Detail part is displayed repeatedly, you can only specify a report source once. Here, we follow the example below:
ActiveReport sub = null;
Private void Detail_Format (object sender, System. EventArgs eArgs)
{
If (sub = null)
{
Sub = new ActiveReports2 ();
This. SubReport. Report = sub;
}
}
Define a global subreport and initialize it in the Detail_Format event.
4. You should also note that the subreport should be released and destroyed after it is used. The specific code should be placed in the ReportEnd event of the main report, for example:
Private void ActiveReports1_ReportEnd (object sender, System. EventArgs eArgs)
{
Sub. Document. Dispose ();
Sub. Dispose ();
Sub = null;
}
5. The rest of the following work is to place the control, set the display fields, load the data, and so on. The previous articles are all described.
The next article describes how to use ActiveReport for. net to develop a cross report.