Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
455
how to create a grand-total row when there are 2 bands and each band already has a sub-total ro
posted

Dear Infragistics UltraGrid Windows Forms Power Users --

Please help.

I need to know how to create a grand-total row when there are 2 bands and each band already has a sub-total row.

So, I have sub-totals of given column, showing the sub-total per-band.

But, at the bottom of the whole grid, I want the grand-total, which would be the sum of each sub-total-per-band, etc.

It currently looks something like this...

http://mkamoski1.files.wordpress.com/2014/02/post_2014_02_07_14_50.jpg

Currently, this is how I am adding the data-columns and the sub-total columns....

//Add a column.

myUltraDataColumnTemp = targetChildBand.Columns.Add(columnKey: DBField._Cost___Component.OD_Component1, dataType: typeof(decimal));

targetGrid.DisplayLayout.Bands[myUltraDataColumnTemp.Band.Key].Columns[myUltraDataColumnTemp.Key].Header.Caption = "OD Component 1";

//Add a summary for the column.

mySummaryBandTemp = targetGrid.DisplayLayout.Bands[myUltraDataColumnTemp.Band.Key];

mySummaryColumnTemp = mySummaryBandTemp.Columns[myUltraDataColumnTemp.Key];

mySummaryBandTemp.Summaries.Add(SummaryType.Sum, mySummaryColumnTemp);

mySummaryBandTemp.Override.SummaryDisplayArea = SummaryDisplayAreas.GroupByRowsFooter | SummaryDisplayAreas.Bottom;

...and that works great and I like it BUT I do not know how to add the grand-total row....

I have done some searching online and but I could NOT find my answers here...

http://ko.infragistics.com/community/forums/p/72749/369704.aspx

http://help.infragistics.com/Doc/WinForms/Current/CLR4.0/?page=WinGrid_Display_Summary_Footers_for_All_GroupBy_Rows.html

http://stackoverflow.com/questions/18053754/displying-grand-total-of-groups-in-grid

http://help.infragistics.com/Help/Doc/WinForms/2011.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.2~Infragistics.Win.UltraWinGrid.UltraGridOverride~SummaryDisplayArea.html

http://ko.infragistics.com/community/forums/p/72749/369704.aspx

...so do you know a quick and easy way to add a grand-total row?

Please advise.

Thanks.

-- Mark Kamoski

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi Mark,

    What you have to do is promote the sum of the child band into a cell in the parent band, then sum the parent column.


            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                UltraGridLayout layout = e.Layout;
                UltraGridBand band0 = layout.Bands[0];
                UltraGridBand band1 = layout.Bands[1];
                band1.Summaries.Add("Column 2 Summary", SummaryType.Sum, band1.Columns["Column 2"]);

                // Create an unbound column in the parent band that will contain the sum of the children
                // of each row
                UltraGridColumn summaryColumn = band0.Columns.Add("Summary");

                // And a grand total summary.
                band0.Summaries.Add(SummaryType.Sum, summaryColumn);
            }

            private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
            {
                if (e.Row.Band.Key == "Band 0")
                {
                    // Populate the unbound cell in the parent band with the value of the sum of the child rows.
                    e.Row.Cells["Summary"].Value = e.Row.ChildBands[0].Rows.SummaryValues["Column 2 Summary"].Value;
                }
            }

Reply Children