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.
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"]); }
I have attached a sample application which illustrates what Mike described. Let me know if I left anything out.