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
965
Summary Column Value based on custom business logic
posted

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?

 

Parents
  • 469350
    Verified Answer
    Offline posted

    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.

Reply Children