Gets or sets a reference to another report to be rendered within the field (a subreport).

Namespace:  C1.C1Report
Assembly:  C1.C1Report.2 (in C1.C1Report.2.dll)


public C1Report Subreport { get; set; }
Visual Basic
<DefaultValueAttribute(Nothing)> _
Public Property Subreport As C1Report


A subreport is a report that is inserted in another report. Subreports are useful when you want to combine several reports into one. For example, you may have a main report that integrates several subreports into a single main report. Or you can use the main report to show detailed information and use subreports to show summary data at the beginning of each group.

For some real-world examples, check the "Sales By Category" and "Sales By Year" reports in the NWIND.XML sample that ships with the control.

To define a field as a subreport, you should start by loading the subreport, then assign the subreport control to the field's Subreport property.

Next, link the subreport to the main report using the subreport field's Text property (this is analogous to setting the LinkChildFields/LinkMasterFields properties in a Microsoft Access subreport). The Text property in a subreport field is used as a filter. It specifies which records in the source recordset should be used to render the subreport based on the current record for the main report.

When the main report is being rendered and reaches the subreport field, the Text expression is evaluated and the result is uses as a filter condition for the subreport.

Building the link expression is not difficult, but it is a little tricky because it requires you to create a string that contains quotes, and these internal quotes must be doubled (written as "").

If you are creating reports using the Report Designer, you don't have to worry about building the link expressions in code. Instead, right-click the subreport field and select the Link Subreport... menu. This will show a dialog where you can select the master and detail fields. When you click OK, the Report Designer will build the link expression and assign it to the Text property of the subreport field automatically.

Subreport fields usually have the CanGrow property set to true, so the subreport field can expand to include all its records.

Subreports may contain other subreports. There's no set limit for the depth of report nesting you can have. However, there must be no circular references to reports. In other words, a report cannot contain a reference to itself as a subreport.


Copy CodeC#
// load subreport and assign it to a field in the main report
string sSub = "Sales By Category Subreport";
c1Sub.Load("NWIND.XML", sSub);
c1rMain.Fields[sSub].Subreport = c1Sub;

// set up connection between main report and subreport
c1rMain.Fields[sSub].Calculated = true;
c1rMain.Fields[sSub].Text = "\"CategoryName = '\" & [CategoryName] & \"'\"";

See Also