Custom grouping

Posted by: salazz on 8 September 2017, 3:18 pm EST

  • Posted 8 September 2017, 3:18 pm EST

    Hello, I would like to help me with an example of how to format the head of a group in your component, for example, a column having numerical data can in its header display the sum of the data in that column belonging to that group. As I explain in the following figure:

  • Replied 8 September 2017, 3:18 pm EST

    Hello,

    Please have a look at attached code and sample which displays sum of each group in group header row:-

    private void Form1_Load(object sender, EventArgs e)
    {
    DataTable table1 = new DataTable();
    DataColumn dc1 = new DataColumn("Product");
    DataColumn dc2 = new DataColumn("Quantity");
    dc2.DataType = System.Type.GetType("System.Int32");
    table1.Columns.Add(dc1);
    table1.Columns.Add(dc2);
    for (int i = 0; i < 20; i++)
    {
    DataRow dr = table1.NewRow();
    if (i % 2 == 0)
    {
    dr[0] = "Apple";
    dr[1] = i + 20;
    }
    else if (i % 5 == 0)
    {
    dr[0] = "Mango";
    dr[1] = i + 30;
    }
    else
    {
    dr[0] = "Orange";
    dr[1] = i + 40;
    }
    table1.Rows.Add(dr);
    }
    fpSpread1.DataSource = table1;
    fpSpread1.Sheets[0].GroupBarInfo.Visible = true;
    fpSpread1.Sheets[0].AllowGroup = true;
    fpSpread1.AllowColumnMove = true;
    fpSpread1.Sheets[0].GroupFooterVisible = true;
    fpSpread1.Grouped += new EventHandler(fpSpread1_Grouped);
    }

    void fpSpread1_Grouped(object sender, EventArgs e)
    {
    FarPoint.Win.Spread.FpSpread ss = (FarPoint.Win.Spread.FpSpread)sender;
    FarPoint.Win.Spread.Model.GroupDataModel gm;
    int total;
    int column = 0;
    if (ss.ActiveSheet.Models.Data.GetType() == typeof(FarPoint.Win.Spread.Model.GroupDataModel))
    {
    gm = (FarPoint.Win.Spread.Model.GroupDataModel)ss.ActiveSheet.Models.Data;
    int i;
    for (i = 0; i < gm.Groups.Count; i++)
    {
    FarPoint.Win.Spread.Model.Group g;
    g = (Group)gm.Groups[i];
    g.Expanded = true;
    total = 0;
    foreach (int r in g.Rows)
    total += (int)gm.TargetModel.GetValue(r, 1);
    column = g.Column;
    g.Text = "Sum (" + total.ToString() + ")";
    }
    }
    }


    Please go through attached sample as well for the same. You can further customize it as per your needs.

    Hope it helps.

    Thanks,
    Reeva

    2015/06/SubTotal.zip
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels