ActiveReports 15 .NET Edition
ActiveReports 15 User Guide / How To / Section Report How To / Common Tasks / Add Groups
In This Topic
    Add Groups
    In This Topic

    In a section report, you can group data by adding a pair of group header and group footer sections to the report. These sections appear immediately above and below the detail section.

    Caution: You cannot add a header section without a corresponding footer section. If you try to do so in code, the results are unstable.

    You can set the properties for the GroupHeader and GroupFooter sections in their corresponding dialogs. Following is a list of properties you can set through the options in these dialogs. Each option in the GroupHeader dialog corresponds to a property in the properties window. To access the properties directly, select the section and open the properties window. See the associated property names in parenthesis with each dialog option below.

    GroupHeader Dialog

    GroupHeader Dialog

    GroupHeader Dialog

    To access the GroupHeader dialog, right click the group header and in the Properties window under the properties list where the commands are displayed, click the Property dialog link. See Properties Window for further information on commands.

    General

    • Name (Name): Indicates the name of the GroupHeader in code. It is unique for a report.
    • Tag (Tag): Indicates the user-defined information persisted with the GroupHeader section.
    • Visible (Visible): Checkbox to specify the visibility of the GroupHeader section.
    • DataField (DataField): Field or expression on which you group the data.

    Appearance

    • Background color (BackColor): Dropdown list to set the background color of the GroupHeader section.

    Layout

    • Insert new page (NewPage): Dropdown list to determine whether a new page is inserted before and/or after displaying the GroupHeader section.
    • Insert new column (NewColumn): Dropdown list to determine whether a new column (in a multi-column report) appears before and/or after displaying the GroupHeader section.
    • Repeat section (RepeatStyle): Dropdown list to specify whether the GroupHeader section appears with every column or page that the Detail section or associated footer appears on.
    • Keep section and its footer on a single page (GroupKeepTogether): Dropdown list to specify whether the GroupHeader section and its footer appear as a single block on the same page or not.
    • Keep section on a single page (KeepTogether): Checkbox to specify whether the GroupHeader section appears on a single page.
    • Keep section and its footer in a single column (ColumnGroupKeepTogether): Checkbox to specify whether the GroupHeader section and its footer appear as a single block in the same column.
    • Keep section underneath the following section (UnderlayNext): Checkbox to specify whether the GroupHeader section appears in the following section or not. It allows you to show group header information inside the group details, so long as you keep the BackColor property of the Detail section set to Transparent.
    • Use column layout (ColumnLayout): Checkbox to determine whether the GroupHeader section uses the same column layout as the Detail section.
    • Can increase to accommodate contents (CanGrow): Checkbox to specify whether the height of the GroupHeader section can grow when its controls extend beyond its original height.
    • Can decrease to accommodate contents (CanShrink): Checkbox to specify whether the height of the GroupHeader section can adjust to the total height of controls placed in it.

    GroupFooter Dialog

    GroupFooter Dialog

    GroupFooter Dialog

    To access the GroupFooter dialog, right click the group footer and in the Properties window under the properties list where the commands are displayed, click the Property dialog link. See Properties Window for further information on commands.

    General

    • Name (Name): Indicates the name of the GroupFooter in code. It is unique for a report.
    • Tag (Tag): Indicates the user-defined information persisted with the GroupFooter section.
    • Visible (Visible): Checkbox to specify the visibility of the GroupFooter section.

    Appearance

    • Background color (BackColor): Dropdown list to set the background color of the GroupFooter section.

    Layout

    • Insert new page (NewPage): Dropdown list to determine whether a new page is inserted before and/or after displaying the GroupFooter section.
    • Insert new column (NewColumn): Dropdown list to determine whether a new column (in a multi-column report) appears before and/or after displaying the GroupFooter section.
    • Keep section on a single page (KeepTogether): Checkbox to determine whether the GroupFooter section appears on a single page.
    • Use column layout (ColumnLayout): Checkbox to specify whether the GroupFooter section uses the same column layout as the Detail section.
    • Print at the bottom of page (PrintAtBottom): Checkbox to specify whether the GroupFooter section is printed at the bottom of the page immediately before the PageFooter section.
    • Can increase to accommodate contents (CanGrow): Checkbox to specify whether the height of the GroupFooter section can grow when its controls extend beyond its original height. 
    • Can decrease to accommodate contents (CanShrink): Checkbox to specify whether the height of the GroupFooter section can adjust to the total height of controls placed in it.

    When you run the report, it renders the group header, followed by all related instances of the detail section, and then the group footer. It renders a new group header section for each instance of the grouping field.

    Controls in the group header render once for each instance of the group, so you can place the column header labels to describe the data in the detail fields here.

    Multiple Grouping

    In a section report, you can nest group header and footer pairs and group each on a different field. You can add up to 32 groupings in one report.

    Note: As with any group header and footer pair, group your data on the fields that you specify in the DataField property of the group header, but in the order of your groups. For example: SELECT * FROM Customers ORDER BY GroupHeader1DataField, GroupHeader2DataField, GroupHeader3DataField

    See the image below for the order in which report sections appear on the report. GroupHeader1 in the image was added first and appears above the other two group headers, while its pair GroupFooter1, appears below the other two group footers.

    Report with multiple grouping

    Report with multiple grouping

    When you run a report with multiple groupings like the one above, the sections print in the following order:

    1. ReportHeader1 prints once and does not repeat.
    2. PageHeader1 prints once at the top of each page.
    3. GroupHeader1 prints once for the first value its DataField returns.
    4. GroupHeader2 prints once for the first value its DataField returns within the context of GroupHeader1's DataField value.
    5. GroupHeader3 prints once for the first value its DataField returns within the context of GroupHeader2's DataField value.
    6. Detail1 prints once for each record that falls within the context of GroupHeader3's DataField value.
    7. GroupFooter3 prints once at the end of the records that fall within the context of GroupHeader3's DataField value.
    8. GroupHeader3 may print again, if more values return within the context of GroupHeader2's DataField value.
    9. Each time GroupHeader3 prints again, it is followed by Detail1 (once for each related record) and GroupFooter3.
    10. GroupFooter2 prints once after GroupFooter3.
    11. GroupHeader2 may print again, if more values return within the context of GroupHeader1's DataField value.
    12. Each time GroupHeader2 prints again, it is followed by Detail1 (once for each related record) and GroupFooter2.
    13. GroupFooter1 prints once after GroupFooter2.
    14. GroupHeader1 prints once for the second value its DataField returns, followed by GroupHeader2, and so on in a pattern similar to the one above.
    15. ReportFooter1 prints once on the last page where the data displayed in the report ends.
    16. PageFooter1 prints once at the bottom of each page. Also, its position within groups varies.  
      Note: At design time, although the PageFooter section is located above the ReportFooter section, at run time it appears after the ReportFooter section on the last page.  

    With many groupings, you might find the need to rearrange the order of your groups. If your report has more than one group, you can right-click the report surface, and select Reorder Groups. This opens the Group Order dialog, where you can drag the groups and set them in any order you want.

    Group Order dialog

    Group Order dialog

    Alternatively, you can also click the Reorder Groups button in the ActiveReports toolbar, to open the Group Order dialog. See Toolbar for further information.

    In a section report, you can set grouping on a field or a field expression. Use the following steps to understand grouping in a section report.

    These steps assume that you have already added a Section Report (xml-based) or Section Report (code based) template and connected it to a data source. See Basic Concepts for further information.

    1. Right-click the design surface of a report and select Insert, then Group Header/Footer. Group Header and Footer sections appear immediately above and below the detail section.
    2. With the GroupHeader section selected, go to the Properties window and set the DataField to a field on which you want to group the data. For example, Country from Customers table in the NWind database.
      Note: You can also set a field expression in the DataField property. For example, =Country + City.
    3. Drag and drop the grouping field onto the GroupHeader section to see the grouping field while previewing the report.
    4. Drag and drop data fields onto the detail section. All the data placed inside the detail section gets grouped according to grouping field.
    5. Preview the report to see the result.

    The following image shows a customer list grouped on the Country field.

    Report with multiple grouping

    Report with multiple grouping

    Tip: In a section report, data is grouped in the order in which it is fetched in the raw form. Therefore, for best results, while setting the SQL query in your report data source, order the data by the grouping field. For example., SELECT * FROM Customers ORDER BY Country