How to force all summaries to recaculate in a WinGrid when a cell value changed?
Hi Axel,
What exactly do you mean by "'import' a saved set of values into a column"? Are you setting the cell values in code? If so, then the summaries should be updating automatically. If they are not, I'd say it's a bug in the grid.
Also, what exactly do you mean when you say "Custom" summaries? I assume this means you are using an ICustomSummaryCalculator. In which case, when you call Refresh on the SummaryValue, the method of the ICustomSummaryCalculator should be called again to calculate the summary value. If this is not happening, then it's a bug.
Do you have the latest Hot Fix?
Sorry about the confusion.
When I said "import" i set the values in the code. But the Summary values aren't updating automatically.
It was suppose to be SummaryType.Formula not Custom (big mistake from my part). I have a couple SymmaryType.Sum and couple SummaryType.Formula...all Sum work and none of the Formla works. All works when I i change a value in the grid but not in the collection.
And I have the latest hotfix. (v8.1.20081.1000)
Manually forcing refresh:
foreach (SummarySettings setting in dgPOI.DisplayLayout.Bands[0].Summaries) { setting.Refresh(); }
Works with manual refresh (SummaryType.Sum):
SummarySettings summary = dgCategory.DisplayLayout.Bands[0].Summaries.Add(SummaryType.Sum, dgCategory.DisplayLayout.Bands[0].Columns["Weight"]); summary.DisplayFormat = "{0:0.00}";
Does not work with manual refresh (SummaryType.Formula):
summary = dgCategory.DisplayLayout.Bands[0].Summaries.Add(SummaryType.Formula, dgCategory.DisplayLayout.Bands[0].Columns["MPRIndex"]); summary.Formula = "sum([mprIndexCalc]) / sum([MPRIndex])"; summary.DisplayFormat = "{0:0.0}";
Co-worker found a work around.
string formula = string.Empty; foreach (SummarySettings setting in ultraGrid1.DisplayLayout.Bands[0].Summaries) { setting.Refresh(); //forces recalc of SummaryType.Sum //Rest is for SummaryType.Formula formula = setting.Formula; setting.ResetFormula(); setting.Formula = formula; }
Enjoy.
I have submited a ticket with the Developer Support with a sample project. I will update this thread with the status of the ticket.
Thanks for your help Mike
************************************************
App: http://es.infragistics.com/TestProjectUploads/GridSummaryTest57200816527283.zip - VS 2005 solution. Should be able to work if you just copy the Win dll to the debug folder.
Steps to reproduce:Unzip. Copy 8.1v of Infragistics2.Win into the exe folder (I had to take it out because of your size req)Run appClick First button This will change the values in the grid but not the summaries
Click Second Button This will force a Refresh() of all the summaries, as you can see only one is updated. The SummaryType.Sum one.Manually change a value in the grid This will make all summaries recalculate
Okay, there are a number of issues here.
First, when you "import" are you setting the values of the cells in the grid? Or are you setting the values in your data source? If it's in the Data Source, then what kind of data source are you using? If your data source is a BindingList, then it should be notifying the grid of the change and the grid shuold automatically update any non-formula summaries. If your data source is a List (as opposed to a BindingList) then it will not send notifications of updates and the grid will not know to refresh, so you will need to refresh the grid and the summaries manually. Maybe you are already doing something that is forcing a refresh on the grid cells.
The second issue is the Formula Summaries. If a value in a cell changes that influences a summary value, then the summary value should update automatically. But again, if you are changing a value through the data source and the data source is not notifying the grid of a change, then we're back to the same limitation as non-formula summaries.
If that's not the case, then it may depend on how you are checking that the summary value has not been updated. If you set a value in a grid cell, for example, and then immiediately try to read out the value of the summary in the next line of code, this will not work. This is correct, because Formulas are (by default) calculated asynchronously. You may be able to get around this by calling the Recalc method on the CalcManager. But theoretically, the SummarySettings.Refresh method should do this for you. If that's not working, then it's a bug and you should Submit an incident to Infragistics Developer Support. If you can include a small sample project demonstrating that it doesn't work, that would be a big help.