Reports for WinForms | ComponentOne
C1.C1Report.CustomFields.4 Assembly / C1.C1Report.CustomFields Namespace / Gradient Class / Subreport Property

In This Topic
    Subreport Property (Gradient)
    In This Topic
    Gets or sets a reference to another report to be rendered within the field (a subreport).
    Syntax
    'Declaration
     
    Public Property Subreport As C1Report
    public C1Report Subreport {get; set;}
    Remarks

    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.

    See Also