Print Search Rate
    
   10-26-2006, 12:10 PM
HOWTO: How to Use the Group Calculation Type sgCalcList.
Attachment: sgCalcList.zip

Using the group calculation type sgCalcList when grouping allows you to create and display a list of data "conditionally" based off the data values of another column. This type is also used in conjunction with the ListSeperator property, which is used to define the separator used to separate the list values.

For example, we have the following grid that we will later group by the month column:

MonthDayInvoiceAmountPaid
11/1/2006I2$760.72$0.00
11/9/2006I28$543.36$543.36
11/27/2006I40$105.45$0.00
11/30/2006I43$191.92$191.92
11/25/2006I78$61.52$61.52
22/6/2006I15$103.02$103.02
22/28/2006I19$162.82$162.82
22/26/2006I34$474.46$474.46
22/16/2006I41$0.24$0.00

Notice that some invoices in the grid have a paid balance of zero.

Next we want create a group with the month column and use the group calculation type sgCalcList to display the list of invoices per group that have an unpaid balance.

MonthDayInvoiceAmountPaid
January - Invoices: I2, I40 (unpaid $866.17)
11/1/2006I2$760.72$0.00
11/9/2006I28$543.36$543.36
11/27/2006I40$105.45$0.00
11/30/2006I43$191.92$191.92
11/25/2006I78$61.52$61.52
Average: $332.59 Total: $1,662.97
February - Invoices: I41, I99 (unpaid $223.98)

Notice we have two groups. The first, "January," is expanded, and the second, "February," is collapsed. Also notice the invoices that equal zero for each group are displayed in the group header of the group.

The code below was used to create the calculated grouping displayed above:

'create a group on the month column Set grp = SGGrid1.Groups.Add("Month", _ sgSortAscending, sgSortTypeNumber, True, False) 'use formulas for header and footer text grp.HeaderTextSource = sgGrpHdrFormula grp.FooterTextSource = sgGrpFooterFormula 'create calculations grp.Calculations.Add sgCalcAverage, "Amount" grp.Calculations.Add sgCalcSum, "Amount" grp.Calculations.Add sgCalcSum, "Amount", "Paid", sgOpEqual, 0 grp.Calculations.Add sgCalcMinimum, "Day" 'The line of code below will create a list of values from our "Invoice" column where the ‘value in the "Paid" column equals 0. With grp.Calculations.Add(sgCalcList, "Invoice", "Paid", sgOpEqual, 0) 'here we specify what we want the list items to be separated by .ListSeparator = ", " End With 'use calculations in formulas grp.HeaderFormula = "Format(GroupCalc(5),'mmmm') & ' - Invoices: ' " & _ "& GroupCalc(4) & ' (unpaid ' & Format(GroupCalc(3),'Currency') & ')'" grp.FooterFormula = "'Average: ' & Format(GroupCalc(1),'Currency') & " & _ "' Total: ' & Format(GroupCalc(2),'Currency')" 'clean up Set grp = Nothing 'refresh the groups SGGrid1.RefreshGroups sgCollapseGroups

You can find additional information about the use of the sgCalcList type, and ListSeperator property from the links to our help file below.

sgCalcList:

http://www.datadynamics.com/Help/SharpGrid/methodSGCalculationsAdd14.html

ListSeperator:

http://www.datadynamics.com/Help/SharpGrid/propertySGCalculationListSeparator7.html

The attached sample uses the code above to display a sgCalcList of values from the "Invoice" column where the value in the "Paid" column equals 0 in our group heading.



Applies To:
SharpGrid 2.0
GrapeCity » Knowledge Base » KnowledgeBase f... » HOWTO: How to Use the Group Calculation Type sgCalcList.
Privacy Policy | Copyright © 1997-2012 — GrapeCity, inc.
All trademarks mentioned are the property of their respective owners.