Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Running total is been miss calculated when i have more than one unbound column to display the running total of certain products.

Displaying the running total of a single products, it is perfectly working, but when i add more unbound columns, the results are not not properly calculated.

for instance for a single product A:

Running total is perfectly calculated
Prod A Cum A
1 1
2 3
3 6

for instance for two products A and B this is the result i get:

Prod A Prod B Cum A Cum B
1 2 3 3
2 4 9 9
3 6 18 18


Any Suggestion?

Regards

What I have tried:

here below is the code i used to calculate the Running total for a single product A:
C#
 private void ProdgridView_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            GridView view = sender as GridView;

            if (e.Column.FieldName == "ACumProd" & e.IsGetData )
            {
                decimal val = 0;
                for (int i = 0; i <= e.ListSourceRowIndex; i++)
                {
                    val = val + (decimal)view.GetRowCellValue(i, view.Columns["ProdA"]);
                    
                }
                e.Value = val;
            }

And For two products A and B 

private void ProdgridView_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            GridView view = sender as GridView;

            if (e.Column.FieldName == "ACumProd" & e.IsGetData || e.Column.FieldName == "BCumProd" & e.IsGetData)
            {
                decimal val = 0;
                for (int i = 0; i <= e.ListSourceRowIndex; i++)
                {
                    val = val + (decimal)view.GetRowCellValue(i, view.Columns["ProdA"]);
val = val + (decimal)view.GetRowCellValue(i, view.Columns["ProdB"]);
                    
                }
                e.Value = val;
            }
Posted
Updated 12-Sep-19 0:28am
v2

1 solution

C#
    for (int i = 0; i <= e.ListSourceRowIndex; i++)
    {
        val = val + (decimal)view.GetRowCellValue(i, view.Columns["ProdA"]);
        val = val + (decimal)view.GetRowCellValue(i, view.Columns["ProdB"]);
    
    }
    e.Value = val;
} 

You are accumulating both totals into the same variable.
 
Share this answer
 
Comments
Maciej Los 12-Sep-19 6:31am    
Hawk eye!
Richard MacCutchan 12-Sep-19 6:41am    
Thank you Chingachgook.
Maciej Los 12-Sep-19 6:44am    
What is "Chingachgook"? I believe that there's something funny...
Richard MacCutchan 12-Sep-19 6:56am    
He was the title character, and companion of Hawkeye the frontiersman, in the novel, "The Last of the Mohicans", by J Fenimore Cooper. An interesting read if you enjoy historical novels.
Maciej Los 12-Sep-19 7:08am    
I know that novel and i've read that. I saw the video too, but i didn't associate "Hawk eye" with "Chingachgook".
In polish version of novel: "Czingaszguk". Different words in spelling, but the pronunciation is the same.
;)
I was thinking about "Hawk eye" as a person who's very perceptive.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900