FlexReport for .NET | ComponentOne
In This Topic
    Sections
    In This Topic

    A flexreport or a .flxr file is divided into sections. These sections can be viewed in the report when you open it in the FlexReportDesigner app. Every report consists of basic sections such as, Report Header, Page Header, Group Header, Detail, Group Footer, Page Footer, Report Footer and Sub-section. The report sections help in partitioning the report vertically. Based on their type (for example, Page, Group, Sub-Section etc.), they are arranged, by default, at specific places within the report.

    The following diagram shows how each section is rendered on a typical report. It also displays how a sub-section in the Detail section is rendered in the report:

    Image showing sections of report

    To create user-friendly reports, you need to understand how each section works. Let us explore each section in the order they appear in the report.

    Report Header
    The first section rendered is the Report Header. It appears only once, in the beginning of a report. This section usually contains information that identifies the report.
    Page Header
    After the Report Header, comes the Page Header. If the report has no groups, this section usually contains labels that describe the fields in the Detail Section.
    Group Headers and Group Footers
    The next sections are the Group Headers, Detail, and Group Footers. These are the sections that contain the actual report data. Group Headers and Footers often contain aggregate functions such as group totals, percentages, maximum and minimum values, and so on. Group Headers and Footers are inserted whenever the value of the expression specified by the GroupBy property changes from one record to the next.
    Detail
    The Detail section contains data for each record. It is possible to hide this section by setting its Visible property to False, and display only Group Headers and Footers. This is a good way to create summary reports.
    Page Footer
    At the bottom of each page is the Page Footer Section. This section usually contains information such as the page number, total number of pages in the report, and/or the date on which the report was printed.
    Report Footer
    Finally, the Report Footer section is printed before the last page footer. It appears only once, towards the end of a report. This section is often used to display summary information about the entire report.
    Sub-section
    The Sub-Section can be added to any section of a report; by default it gets added at the bottom of the section that is currently selected. This section contains the additional data that enhances the data present in its parent section. A section’s height is determined by the sum of heights of its sub-sections.

    Sub-section

    Sub-sections are the additional sections that can be added to any section of a report. A FlexReport generally contains - Detail, Header, Footer, PageHeader, Page Footer, Group Header and Group Footer. You can add as many sub-sections as required in a section. This can be done via the FlexReportDesigner application or through code.

    Add Sub-sections

    Sub-Sections can be added to any section of a report. By default, the sub-section gets added at the bottom of the currently selected section.

    For instance, let's say you want to add a sub-section in the Page Header. This can be easily achieved via the FlexReportDesigner as well as through code:

    1. Move the cursor to the section of the report where you want to add the sub-section.
      Image for tooltip in subsection
    2. Select the section and right-click to view the context menu. Click the Add SubSection option.

      Image for adding subsection

    Now, you can observe that a sub-section is added below the Page Header. Move the cursor to the sub-section to view the tooltip that says it is the first subsection of the Page Header section.

    Image for subsection from Page header

    You can also add a sub-section in the Page Header section of a report programmatically. To illustrate the addition of a sub-section to an existing section like Page Header, we are using the Report Creation sample used to create a report definition.

    The snapshot of the resulting output is given below:

    Creating a subsection from code

    In the code snippet below, we will add a subsection to the Page Header using SubSections property of the SubSectionCollection class, and add fields to this sub-section using Fields property of the SubSection class. We have also added a backcolor to the sub-section, just to highlight it.

    C#
    Copy Code
    // create a subsection in the page header section
    SubSection ss = c1FlexReport1.Sections.PageHeader.SubSections.Add();
    // set height to 10 mm
    ss.Height = 10 * 1440 / 25.4;
    // assign a backcolor to highlight the sub-section
    ss.BackColor = Color.Lime;
    // add fields to the subsection
    TextField textFieldB = new TextField();
    textFieldB.Name = "FldID";
    textFieldB.Text.Expression = "EmployeeID";
    textFieldB.Left = 0;
    textFieldB.Top = 0;
    textFieldB.Width = 400;
    textFieldB.Height = 300;
    ss.Fields.Add(textFieldB);
    // add fields to the subsection
    TextField textFieldA = new TextField();
    textFieldA.Name = "FldFirstName";
    textFieldA.Text.Expression = "FirstName";
    textFieldA.Left = 500;
    textFieldA.Top = 0;
    textFieldA.Width = 900;
    textFieldA.Height = 300;
    ss.Fields.Add(textFieldA);
    

    Split FlexReport Objects

    Since creating reports is all about representing data, it is important to determine the sub-section behavior when its too large to fit within the vertical space available on the current page.

    In FlexReports, any Section or Sub-section can be forced to split or not to split (keep together) between the pages by setting SplitBehavior property to SplitIfNeeded or KeepTogether.

    The KeepTogether option lets the object to be split only if it is too large to fit on an empty page. If that's the case, then the object is split immediately. Otherwise, a new page is started and the object is placed on it without splitting. While, the SplitIfNeeded option lets the object to be split if it does not fit onto the current page.

    Similarly, the splitting of Fields and Borders is governed by SplitHorzBehavior and SplitVertBehavior properties. The SplitHorzBehavior property determines how the borders are drawn for an object if it is too wide and split between pages. On the other hand, the SplitVertBehavior property determines how the borders are drawn for an object if it is too high and split between pages.

    The following code sets the SplitBehavior for a Section and a Sub-section:

    C#
    Copy Code
    // Allow section to split if needed
    c1FlexReport1.Sections.Header.SplitBehavior = SplitBehavior.SplitIfNeeded;
    // Allow sub-section to split if needed
    c1FlexReport1.Sections.Header.SubSections[0].SplitBehavior = SplitBehavior.SplitIfNeeded;
    

    Customize Sections

    You can determine whether or not a section is visible by setting its Visible property to True or False. Group Headers can be repeated at the top of every page (whether or not it is the beginning of a group) by setting their Repeat property to True. Page Headers and Footers can be removed from pages that contain the Report Header and Footer sections by setting the PageHeader and PageFooter properties on the Layout object.

    Note that sections can be made invisible, but they cannot be added or removed, except by adding or removing groups.