Subtotals within Grouping

Posted by: hpadmasola1 on 8 September 2017, 2:47 pm EST

  • Posted 8 September 2017, 2:47 pm EST

    I have the GroupBar activated and visible on my grid. When I drag a column It groups it by that column and shows the data. I also want to show subtotals within each group. Is that possible ?

     Thanks

    Harish

  • Posted 8 September 2017, 2:47 pm EST

    subtotals of what?

  • Posted 8 September 2017, 2:47 pm EST

    When I drap a column on to the group bar, the grid shows the data grouped by the dragged column. Right ? now, There could be some columns with numbers in the data. I need the totals showing for each group. I hope I made that clear.

    Harish 

     

     

     

  • Posted 8 September 2017, 2:47 pm EST

    Group footers can

    show subtotals.  Please refer to the SpreadWinDemo sample,

    columnGroupFooter form, which shows how to use SheetView.DefaultGroupFooter to

    set aggregation formulas in the footer cells.







  • Posted 8 September 2017, 2:47 pm EST

    I used the following code for it to work. Its creating a blank row below each group. But I dont see the subtotals. Here is the code Iam using.

     

    fpspread1.Sheets(0).GroupFooterVisible = true

    fpspread1.Sheets(0).ColumnFooter.SetAggregationType(0, 3, FarPoint.Win.Spread.Model.AggregationType.Sum)

    fpspread1.Sheets(0).ColumnFooter.SetAggregationFormat(0, 3, "{0}")

     

     any help is appreciated.

    Harish

  • Posted 8 September 2017, 2:47 pm EST

    Hello,

    I would like you to know that your requirement is having subtotal in the GroupFooter and you are setting the AggregationType for the ColumnFooter, hence you are not getting the sum in each group. You would need to use the SetCellAggregationType method for the GroupFooter in the Grouped event for getting the subtotal for each group, and displaying it in the GroupFooter. I have created a sample depicting the same, kindly have a look at it.

    Hope it will help you. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur.

    2011/10/subtoatal.zip
  • Posted 8 September 2017, 2:47 pm EST

    manpreet,

      Thats awesome. It works great.

    Thanks a lot.

    harish

  • Posted 8 September 2017, 2:47 pm EST

    one more Question. If I do a grouping by two columns, (I drag a country column and also drag SalesPerson column on to the group Bar. I see totals for country level. I need to show totals at the salesPerson level within each country.

    I guess I need another for loop within the outer for loop. right ? Can you help me with that ?

    Thanks

    harish

  • Posted 8 September 2017, 2:47 pm EST

    Hello,

    I have created a sample that fullfills your requirement to perform sum of the column at second level of grouping. So, the sample sums the columns at both levels of grouping that is first and second, in case you want grouping only at the second level, you would need to comment two statements in the attached sample, which are indicated in the sample.

    Kindly, have a look at the same. Hope it will help you. Please let me know if you have any queries further.

    Thanks, 

    Manpreet Kaur

    2011/10/subtoatal-2.zip
  • Posted 8 September 2017, 2:47 pm EST

     

    Great. It works well. One final question. How do I right justify the totals in each cell ?

     Harish

  • Posted 8 September 2017, 2:47 pm EST

    Hello,

    You would need to create an instance of the GroupInfo class, and set the alignment of the information in the group footer, by using the HorizontalAlignment property of the instance created. I have modified the sample to depict the same, kindly have a look at it.

    Hope it will help you. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur.

    2011/10/subtoatal-3.zip
  • Posted 8 September 2017, 2:47 pm EST

     

    Excellent. It all works.

    manpreet, you are a rock star.

    Harish

  • Posted 8 September 2017, 2:47 pm EST

    Manpreet, could you attach a project using the latest version of Spread v5, and vb.net? think it could help me in my problems with subtotals and models Smile 

    thanks in advance...

  • Posted 8 September 2017, 2:47 pm EST

    Hello,

    I have attached a Vb.Net sample created using the latest version of Spread for Windows Forms v5, i.e. v5.0.xx22 depicting the subtotals in grouping. Kindly have a look at it. Hope it will help you. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur

    2012/08/SubtotalsVB.zip
  • Posted 8 September 2017, 2:47 pm EST

    Thank you; once again problem with Spread version:

    "Error 18 Unable to resolve type 'FarPoint.Win.Spread.FpSpread, FarPoint.Win.Spread, Version=5.0.3522.2008, Culture=neutral, PublicKeyToken=327c3516b1b18457' H:\NET_CodeSamples\ProjektyTestowe\SubtotalsVB\My Project\licenses.licx 1 SubtotalsVB"

    I have 5.0.2008.35.FarPoint.Win version; changed references in diferent ways - surrended... no way to run

    sorry for problems.

  • Posted 8 September 2017, 2:47 pm EST

    Hello,

    As you asked for a sample in the latest version of Spread for Windows Forms V5 i.e V5.0.3522, I provided you with a sample using the same. So, I would suggest you to download the latest version of Spread for Windows Forms V5 i.e V5.0.3522 from the following link:

                ftp://ftp.fpoint.com/SpreadWinForms5/

    Please uninstall any old versions from your system and install this latest version. You would be able to run the project once you have the dll's for the latest version used in the project available in your system. In case you want to run the sample with the old version Spread for Windows Forms V5 installed on your system, here are the steps to run the project:

    1. Open the project in VS2010, click on the references folder in the solution explorer, select and remove all the FarPoint dlls.

    2. Now open the properties tab in the solution explorer and delete the licenses.licx  file.

    3. Click on the references folder and add the FarPoints dlls present on your system for the current version of Spread for Windows Forms installed on your system.

    4. Open the form named "Form1" in the project in the designer, it would add the licenses.licx  file with the correct entries.

    Now, debug the project and it would run without any issues. Hope it will help you. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur

     

     

  • Posted 27 March 2019, 2:33 am EST - Updated 30 September 2022, 1:57 pm EST

    Hi,

    • We are displaying the column values in the grid with tree format by using C1FlexGrid.

    • We have migrated the Component One version from 2.0 to 4.0 in our winform application.

      After migration subtotal of each group is not getting displayed in the group header, its getting added to the first group header subtotal.

    Configuration setting before Upgrade :

    My application was developed in vb.net VS2003. We were used the following component one dll as below.

    C1.Win.C1FlexGrid.dll V2.6

    C1.Win.C1Command.dll V1.0

    C1.Common.dll V1.0

    C1.C1Zip.dll V1.0

    C1.Win.C1Sizer.dll V1.1

    b]Configuration setting after Upgrade :[/b]

    We migrated the code VS2003 from VS2015. We were used the following component one dll as below.

    C1.Win.C1Sizer.4.dll V 4.0

    C1.Win.C1FlexGrid.4.dll V4.0

    C1.Win.C1Command.4.dll V 4.0

    C1.C1Zip.4.dll V 4.0

    After grouping we are doing reaggregate as below:

    Private Sub RecalculateAggregates()

    ’ Assumption: row order doesn’t need to change, we just need to

    ’ recalculate the aggregate entries.

    fGrid.Redraw = False

    Try

    For Each agr As Flex.Column In GetCols(Grouping.AggregateCols)

    Dim level As Integer = 0

    For Each grp As Flex.Column In GetCols(Grouping.GroupCols)

                    fGrid.Subtotal(Flex.AggregateEnum.Sum, level, grp.Index, agr.Index, "{0}")
    
                  
                    level += 1
                Next
            Next
            RemoveZerosFromAggregations()
        Finally
            fGrid.Redraw = True
        End Try
    End Sub
    

    We have not change an functionality as part of this migration, could you please help me on this subtotal issue in each group header. PFA screenshot for your reference with before and after upgrade of componentone.

Need extra support?

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

Learn More

Forum Channels