Adding a Formula on a Summary column by programmation

Hi,

I am using a GridGroupingControl
I have 3 column

SalesPrice
AlreadyChargePourcentage
AmountAlreadyCharge

I put a Summary column on the SalesPrice and AmountAlreadyCharge column

What I would like to do for the AlreadyChargePourcentage column is to take the total the AmountAlreadyCharge column divide by the total of the SalesPrice column

How can I do that by programmation?
Is that possible?

Thanks in advance and have a nice day!








4 Replies

AD Administrator Syncfusion Team May 28, 2008 01:02 PM UTC

One way you can do this is to add a 'placeholder summary' where you want to see the custom calculation. Then handle the QueryCellStyleInfo event and explicitly provide the value of this placeholder summary at the proper time. Here is a minimal sample that shows this technique.
http://www.syncfusion.com/support/user/uploads/CustomSummary_56e925f5.zip



GC Gilles Carreau May 28, 2008 08:44 PM UTC

Hi,

I try to use your code sample in my project
It look like i dont have the right version of the grouping control

Is that possible ?
My version is 2.1.0.9

Does your sample should work with this version?

This line does not pass the compilation
TypeOf e.TableCellIdentity.DisplayElement Is GridSummaryRow

The compiler say that a DisplayElement can never be a gridSummaryRow

What do you think?

Thanks in advance




AD Administrator Syncfusion Team May 28, 2008 10:25 PM UTC

I am using 6.3.0.6, the latest version.

Here is a VB snippet that works for me with the 6.3.0.6 version.

Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
'If TypeOf e.TableCellIdentity.DisplayElement Is GridSummaryRow AndAlso Not (e.TableCellIdentity.SummaryColumn Is Nothing) AndAlso e.TableCellIdentity.SummaryColumn.Name = "sumCol1" Then
If Not (e.TableCellIdentity.SummaryColumn Is Nothing) AndAlso e.TableCellIdentity.SummaryColumn.Name = "sumCol1" Then

Dim row As GridSummaryRow = e.TableCellIdentity.DisplayElement '

e.Style.BackColor = Color.LightGoldenrodYellow
Dim dCol2, dCol3 As Double
If Double.TryParse(GridEngine.GetSummaryText(row.ParentGroup, "sumRow", "sumCol2"), dCol2) And Double.TryParse(GridEngine.GetSummaryText(row.ParentGroup, "sumRow", "sumCol3"), dCol3) And Math.Abs(dCol3) > 0.0000001 Then
e.Style.CellValue = dCol2 / dCol3
End If
End If
End Sub 'gridGroupingControl1_QueryCellStyleInfo




GC Gilles Carreau May 29, 2008 12:33 PM UTC

Hi,

I already try this code yesterday
Like I said it does not pass the compilation

I have an old version of the grid Syncfusion
so that might be the problem

Anyway I want to thank you for your support

Have a nice day!


Loader.
Up arrow icon