I am adding a summary row to about 20 Grids in our application.
Some of the columns only need to be summed or show a max value so I have used the following code to do this.
grid1.DisplayLayout.Bands[0].Summaries.Add("Column1", SummaryType.Sum, grid1.DisplayLayout.Bands[0].Columns["Column1"]);grid1.DisplayLayout.Bands[0].Summaries["Column1"].DisplayFormat = "{0}";
grid1.DisplayLayout.Bands[0].Summaries.Add("Column2", SummaryType.Maximum, grid1.DisplayLayout.Bands[0].Columns["Column2"]);grid1.DisplayLayout.Bands[0].Summaries["Column2"].DisplayFormat = "{0}";
Other columns need to be calculated based on custom business logic.
For example the value in Column5 is determined by ... if Column2 > 25 we multiple Column1 by Column3, if Column2 < 25 we divide Column1 by Column4.
This is an example and some of the calculations are more complicated than this so I don't believe using UltraCalcManager Formulas is not the answer.
I'd like to create a function that calculates the Value based on other summary values. I looked at the ExternalSummary functionality but am not sure how to populate the values based on a function?
Hi,
There are a couple of different approach you can take here.
You could use external summaries and calculate the summary value yourself. I'm not quite sure what you mean by "populate the values based on a function", though, or what part of this is giving you trouble exactly. All you have to do is handle the ExternalSummaryValueRequested event and return the value you want for the summary. You will need to loop through the rows and do the calculation yourself, of course.
Another option would be to use the Custom summary type and provide an ICustomSummaryCalculator. This is essentially the same thing, but it handles looping through the row for you, and it might be a little cleaner and more efficient.
Another option, for a conditional summary like you described here where your summary is based on more than one column would be to perform the calculation in multiple steps using an unbound column. For example, let's say you have a column "A" and you want a sum of column "A", but you only want to include the rows where column "B" is true. You could create an unbound column in the grid and use the InitializeRow event to calculate the value of an unbound column. The unbound cell's value would be "A" is "B" is true, otherwise 0. Then you could sum up the unbound column.
Thank You. I used a number of the options you suggested based on the needs of each column.
Not sure if this is a recommended way to do things but in one Column I wanted to display 2 unbound integer columns as a fraction so I did the following.
Band.Summaries["FractionColumn"].DisplayFormat = ugGrid.Rows.SummaryValues["UnboundColumn1"].Value.ToString() + "/" + ugGrid.Rows.SummaryValues["UnboundColumn2"].Value.ToString();
I guess that will work. The weird part about that is that if you try to access the Value of the summary, it won't return what's displayed.
Another option would be to use an External summary and ignore the ExternalSummaryValueRequested event, but instead to simple assign the Value of the summary whenever you want. For a summary on the root band you would do something like this:
ugGrid.Rows.SummaryValues["FractionColumn"].SetExternalSummaryValue(ugGrid.Rows.SummaryValues["UnboundColumn1"].Value.ToString() + "/" + ugGrid.Rows.SummaryValues["UnboundColumn2"].Value.ToString());