Page tree
Skip to end of metadata
Go to start of metadata

分组是最常用表示数据的组织结构的方法。设计基本布局后,您可以按某些字段或其他条件来分组以分隔记录,以使报表更易于阅读。通过对数据进行分组,您可以将记录组分开,并为每个组显示介绍性数据和摘要数据。分组基于分组表达式。此表达式通常基于一个或多个记录集字段,也可以根据需要设置一些复杂的条件。

在FlexReport中,通过使用C1FlexReport.Groups实现分组  。

例如您要查看每个职称的员工列表。在这种情况下,列表应按标题分组。以下步骤说明了如何按标题对雇员列表进行分组。本示例使用FlexReport快速入门中创建的示例  。

  1. 将一个C1CheckBox添加 到FlexReport快速入门项目的表单中。
  2. 将C1CheckBox 名称设置  为“ groupC1CheckBox”,将文本设置为“按职称分组报表”。
  3. CheckedChanged事件创建为c1CheckBox1_CheckedChanged。

    CS
    Group grp;
    Section s;
    private void c1CheckBox1_CheckedChanged(object sender, EventArgs e)
            {
                if (groupC1CheckBox.Checked)
                {
                 // group employees by title and sort titles in ascending order         
                    grp = c1FlexReport1.Groups.Add("GrpTitle", "Title", SortEnum.Ascending);
                 // format the Header section for the new group           
                    s = grp.SectionHeader;
                    s.Height = 1000;
                    s.Visible = true;
                   
                    TextField f = new TextField();
                    f.Name = "Title";
                    f.Text.Expression = "Title";
                    f.Left = 0;
                    f.Top = 0;
                    f.Width = c1FlexReport1.Layout.Width;
                    f.Height = 500;
                    f.Align = FieldAlignEnum.LeftMiddle;
                    f.Font.Bold = true;
                    f.Font.Size = 12;
                    f.Border = new Border(2, Color.Black, DashStyle.Solid);
                    f.BackColor = Color.FromArgb(150, 150, 220);
                    f.MarginLeft = 100;
                    s.Fields.Add(f);
                    c1FlexReport1.Render();                                
                }
                else
                {
                    btnEmployees.PerformClick();
                }
            }
  4. 运行项目。单击员工按钮以呈现报表。
  5. 单击“按职称分组报表”复选框以查看报表分组。观察Title以升序排列。
    在FlexReport中对数据进行分组

  • No labels