Group Data

Grouping is the most commonly used method to represent data in an organized manner. After designing the basic layout, you may decide to segregate the records by certain fields, or other criteria that would make the report easier to read. By grouping data, you can separate groups of records and display introductory and summary data for each group. The group break is based on a grouping expression. This expression is usually based on one or more recordset fields but it can be as complex as you want.

In FlexReport, grouping is achieved by using C1FlexReport.Groups.

Let us say you want to view a list of employees falling under a designation or title. In this case, the list should be grouped by Title. The following steps illustrate how to Group the list of employees by the Title. This example uses sample created in FlexReport Quick Start.

  1. Add a C1CheckBox to the XAML design in the Quick Start project.
  2. Set the Name of C1CheckBox to 'groupC1CheckBox' and Content to 'Group Report by Title'.
  3. Create Checked event as c1CheckBox1_Checked.
  4. Add the following code to group the list of employees by Title:
    Dim grp As Group
    
    Private Sub c1CheckBox1_Checked(sender As Object, e As RoutedEventArgs)
        ' group employees by title and sort titles in ascending order         
        grp = rep.Groups.Add("GrpTitle", "Title", SortEnum.Ascending)
        ' format the Header section for the new group           
        s = grp.SectionHeader
        s.Height = 1000
        s.Visible = True
    
        Dim f As New TextField()
        f.Name = "Title"
        f.Text.Expression = "Title"
        f.Left = 0
        f.Top = 0
        f.Width = rep.Layout.Width
        f.Height = 500
        f.Align = FieldAlignEnum.LeftMiddle
        f.Font.Bold = True
        f.Font.Size = 12
        f.Border = New C1.WPF.Document.Border _
        (2, Color.FromRgb(0, 0, 0), C1.WPF.Document.DashStyle.Solid)
        f.BackColor = Color.FromRgb(150, 150, 220)
        f.MarginLeft = 100
        s.Fields.Add(f)
        rep.Render()
    End Sub
    
  5. Run the project. Click Employees button to render the report.
  6. Click 'Group Report by Title' checkbox to view the grouping in the report. Observe that the list of employees are grouped by Title and titles are sorted in the ascending order.