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
1205
WinGrid Summary
posted

My objective is to perform this calculation: Field2/Field1 = Field3.

this.ugSalesStats.DisplayLayout.Bands[0].Summaries.Add("Field1", SummaryType.Sum, this.ugSalesStats.DisplayLayout.Bands[0].Columns["Field1"]); this.ugSalesStats.DisplayLayout.Bands[0].Summaries.Add("Field2", SummaryType.Sum, this.ugSalesStats.DisplayLayout.Bands[0].Columns["Field2"]);     this.ugSalesStats.DisplayLayout.Bands[0].Summaries.Add("Field3", SummaryType.Sum, this.ugSalesStats.DisplayLayout.Bands[0].Columns["Field3"]);

I'm aware the above syntax won't get it done. My intent above is to illustrate what I'm trying to accomplish.

I've read several KB articles related to my objective but I can't quite figure out the appropriate syntax.

To sum it up, I want to divide two summery row fields and place the result in a third summay row field.

Field1    Field2    Field3

 1234       711        57

Thanks for taking a look.

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi,

    There's no way to do this using the built-in summary types like SummaryType.Sum. But you could do it using Formula summaries.

    First, make sure you have an UltraCalcManager component on the form with the grid. You need it in order to use formulas.

    When you add your summaries, you need to specify a Key and a formula for each one.


            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                UltraGridLayout layout = e.Layout;
                UltraGridBand band = layout.Bands[0];

                band.Summaries.Add("Field1Sum", "Sum([Field 1])",  SummaryPosition.UseSummaryPositionColumn, band.Columns["Field 1"]);            
                band.Summaries.Add("Field2Sum", "Sum([Field 2])", SummaryPosition.UseSummaryPositionColumn, band.Columns["Field 2"]);

                // When referencing a summary in a formula, you have to use parens at the end of
                // the summary key. This is so the grid can distinguish a summary key from a  
                // column key.
                band.Summaries.Add("Field3Sum", "[Field1Sum()] / [Field2Sum()]", SummaryPosition.UseSummaryPositionColumn, band.Columns["Field 3"]);
            }

Children