Hi All,
I recently started using Infragistics controls and I've got a UltraWinGrid in NetAdvantage 2008 Vol 2 where I have column summaries configured. If rows in a column are null (never assigned anything), it screws up the summary 'average/min' calculations since it appears these cells are implied to be '0'.
Is there anyway to get a proper calculation of summaries like 'count/average/min' when there are null cells? Or perhaps to populate the 'dead' cells with some _invisible_ constant to prevent them from being used in the calculations?
Thanks!
Corey.
Hi Corey,
How are you doing the summaries? Are you using a Formula or one of the built-in summary types?
The grid doesn't really have any way to know whether or not empty cells should be included in a summary calculation or not. So it assumes they do.
If you are using the built-in summaries, then you would get around this by using a custom summary and writing your own ICustomSummaryCalculator.
If you are using formulas, you will need to create your own functions that ignore empty values.
Thanks for the reply, Mike.
Yes, I'm using the built-ins - I'm only interested in 'sum' at this stage. I took your advice and created a class derived from ICustomSummaryCalculator. All the samples that I have seen, however, seem to just return one single value. I am interested in summations for every column that I add the Summary to.
I'm assuming the proper place to do the summation is in AggregateCustomSummary, but that method is row based. I can build up the column sums easily enough as the rows are processed, but how to then get the column totals to be populated in the summation line in the grid? Does EndCustomSummary somehow set and return the new summary row? Or is the summary info yet another 'row'?
CoreyW said: I am interested in summations for every column that I add the Summary to.
I'm not sure I follow you here. You simply add summaries to each column however you want. Each summary would have an ICustomSummaryCalculator. I'm not even sure if you need a new instance of the class for each one, you might be able to just create a single instance of your class and use it of every column. But if that doesn't work, just create a new instance for each summary you need and it should not be a big deal.
CoreyW said:I'm assuming the proper place to do the summation is in AggregateCustomSummary, but that method is row based. I can build up the column sums easily enough as the rows are processed, but how to then get the column totals to be populated in the summation line in the grid? Does EndCustomSummary somehow set and return the new summary row? Or is the summary info yet another 'row'?
Your class which implements ICustomSummaryCalculator should keep a member variable for the total (sum).
In the BeginCustomSummary, you reset the member variable to 0.
In AggregateCustomSummary, you examine the row and get the value from the appropriate cell. If it's null, you do nothing, otherwise, you add it to the total.
In the EndCustomSummary, you simply return the value of the member variable.
public class MySumCalculator : ICustomSummaryCalculator { int sum = 0; #region ICustomSummaryCalculator Members void ICustomSummaryCalculator.AggregateCustomSummary(SummarySettings summarySettings, UltraGridRow row) { object value = row.Cells[summarySettings.SourceColumn].Value; if (value is DBNull || value == null) return; int i = (int)value; this.sum += i; } void ICustomSummaryCalculator.BeginCustomSummary(SummarySettings summarySettings, RowsCollection rows) { this.sum = 0; } object ICustomSummaryCalculator.EndCustomSummary(SummarySettings summarySettings, RowsCollection rows) { return this.sum; } #endregion }
Of course, there really isn't much point in doing this for a Sum. The sum already treats nulls as 0's, so this will do the same thing the grid already does.
For an average where you want to ignore nulls, you would do essentially the same thing, except that in addition to the sum, you would also keep track of the count and only count non-nul values. Then you could calculated the average based on the actual values that are not null.