FlexReport for .NET | ComponentOne
Reports in WinForms / Group Data
In This Topic
    Group Data
    In This Topic

    Grouping is a common method for organizing data. After designing the basic layout, you may choose to segregate records by specific fields or criteria to make the report easier to read. Grouping data allows you to separate sets of records and display introductory and summary data for each group. The group break is determined by a grouping expression, which is typically based on one or more recordset fields but can be as complex as needed.

    In FlexReport, grouping is achieved using FlexReport.Groups. For example, if you want to view a list of products based on suppliers who supply multiple products, you would group the list by Supplier. The following steps illustrate how to group the list of products by Supplier in the report:

    1. In the design view, add a FlexReport, a Button and a FlexViewer control.
    2. Set the Name property of the FlexReport control to flexReport, Button control to btnGroup and the FlexViewer control to flexViewer.
    3. Create a data table with the name GetMyDataTable and add the code to load and render the report as shown in DataTable object as DataSource section of the Data Binding topic.
    4. Add the following code in the Click event of the Button control for grouping the data in the report. In the code, an object of the Group class is created and added to the Groups collection of flexReport using the Add method. The object of the Section is created to style the band while displaying name of the suppliers.
      C#
      Copy Code
      Group grp;
      
      grp = flexReport.Groups.Add("Supplier", "Supplier", SortEnum.Ascending);
      
      C1.Win.FlexReport.Section s;
      s = grp.SectionHeader;
      s.Height = 1000;
      s.Visible = true;
      
      TextField f = new TextField();
      f.Name = "Supplier";
      f.Text.Expression = "Supplier";
      f.Left = 0;
      f.Top = 0;
      f.Width = flexReport.Layout.Width;
      f.Height = 500;
      f.Align = FieldAlignEnum.LeftMiddle;
      f.Font.Bold = true;
      f.Font.Size = 12;
      f.Border = new C1.Win.Document.Border(2, Color.FromArgb(0, 0, 0), C1.Win.Document.DashStyle.Solid);
      f.BackColor = Color.FromArgb(150, 150, 220);
      f.MarginLeft = 100;
      
      s.Fields.Add(f);
      
      flexReport.Render();
      
      Note: Replace the C1.Win.Document with C1.Win.C1Document in the code for .NET Framework.
    5. Run the application to view the report.
    6. Click the Group button to group the data in the report. The records get appeared in groups on the basis of a supplier supplying different products. Observe the output as illustrated by the below image.

      Grouping data