Hi,
Firstly apologies if this is a simple mistake on my part or has been covered elsewhere but I've just started back with the grid and calc manager and am struggling to get the attached to work (VS2010 with 2013.2075)
Simple project attached and when I click in the new row the formula for column d doesn't appear to work but it works fine for existing rows. If I change the DeferredCalculationsEnabled to True on the calc manager then it works fine but my summary isn't fully calculated unless the grid is fully scrolled. I've tried various combinations of the DeferredCalculationsEnabled and CalcFrequency but just can't seem to get it to give a complete summary and complete the formula for a new row.
Any help greatly appreciated.
Thanks
Hello,
The DeferredCalculationsEnabled will set the calculations on the visible objects. In this case, the visible rows. If you run the sample the with this property set to True, then the scrolling is required to get grand total for all your rows.
Can you clarify by the following?
when I click in the new row the formula for column d doesn't appear to work but it works fine for existing rows
After adding a new row to your data, the calcmanager auto detects and adds it the entry to the total. Does this occur for you?
Mike / Michael, thanks for looking into this for me. I think the summary might be confusing things a little but I'll come back to that. So if deferred calcs are:
- TRUE - then when I click the add row the formula in column d is prefilled with a 0 and works should you enter a value in column a and tab to column b, you don't need the row to be added full. Editing existing rows work the same.
- FALSE - then when I click the add row the formula in column d doesn't get prefilled or work until the row is actually added to the grid fully. However, editing an existing row then changes in d are immediately apparent on leaving a cell but without leaving the row
If I didn't care about the summary I could just change the deferred calcs to TRUE and all would be well. However, I'd like a summary at the top showing the summary of all rows not just those visible initially or that have been scrolled into view. To do this I need to set deferred calcs to FALSE.
I think this makes my requirements a bit clearer but if not let me know. As I say there may be some combination of something I'm missing or I might be going about things in the wrong way.
Thanks in advance for your thoughts.
Sorry, this was my fault. I thought the sample had DeferredCalculationsEnabled set to true.
Anyway, you can still get it to work, but you have to turn off DeferredCalculationsEnabled temporarily when calculating the summary:
Friend Sub BeginCustomSummary(summarySettings As Infragistics.Win.UltraWinGrid.SummarySettings, rows As Infragistics.Win.UltraWinGrid.RowsCollection) Implements Infragistics.Win.UltraWinGrid.ICustomSummaryCalculator.BeginCustomSummary CType(ultraCalcManager, Infragistics.Win.UltraWinCalcManager.UltraCalcManager).DeferredCalculationsEnabled = False Dim columnRef As IUltraCalcReference = ultraCalcManager.GetReference("//UltraGrid1/abc/d") ultraCalcManager.EnsureCalculated(columnRef, True) CType(ultraCalcManager, Infragistics.Win.UltraWinCalcManager.UltraCalcManager).DeferredCalculationsEnabled = True Me.invoiced = 0 Me.paid = 0 End Sub
Although the more I think about it, the more I realize that DeferredCalculationsEnabled isn't really giving you a lot of benefit here. Since you have a a summary at the top of the grid, everything has to be calculated immediately, anyway, in order for the summary calculation to be accurate. So unless the summary is scrolled out of view and you make a change, the calculations can almost never be deferred.
Mike and Michael, many thanks for your help on this issue. I think we've all spent plenty of time on this already and it does appear, to me, that there isn't an easy solution to this. I thought originally I might just be missing something and a quick change of property values would sort it out. In summary and to clarify what I'm seeing with the last few posts:
1. Summary not working when deferred calcs is TRUE initially - having inserted the extra lines of code in the previous post then yes I agree that the summary now does work as expected without scrolling to the bottom of the grid. However, template row doesn't work.
2. I've checked the template issue in isolation again using 2014.1 and it still doesn't work with deferred calcs set to FALSE initially. I think it may appear to work in your sample as you set the value to TRUE in the BeforeEnterEditMode event.
After playing a little again the best value in my situation for deferred calcs is TRUE as it allows the template to work and the summary even updates when the template is getting updated. The only issue being that as you've already said, Mike, is that the rows out of view don't have column d populated until scrolled into view. I've now got around that in the AggregateCustomSummary with the following line of code (sorry not sure how to insert code in reply like you've done):
If row.Cells("d").Value Is Nothing Then row.Cells("d").Value = CDec(row.Cells("a").Value) + CDec(row.Cells("b").Value)
This does mean the formula is sort of duplicated within the code but never mind. There may be a better / more robust way of updating the cell value or testing that it's not been calculated and if so I'd be grateful for advice on that.
Once again thanks for all your help and I think it's time to move on....
You are correct. I didn't notice that the sample project was working around the problem by setting DeferredCalculationsEnabled to true in BeforeEnterEditMode. So the issue with the TemplateAddRow still exists.
I will re-open the issue and we will look into this again and try to get it fixed. Once that issue is fixed, then you should be able to achieve what you want by setting DeferredCalculationsEnabled to false.
Once again, I apologize for the confusion.
No worries Mike, I'll await the outcome of your investigation.
So we took another look, and it looks like fixing this in the control would be extremely dangerous and have a high potential for breakage.
The good news is that I found another workaround that I think should be acceptable and get you what you want. In fact, I am pretty sure this workaround will fix both of the issues you reported here, and alleviate the need for the changes in your custom summary calculator.
All you have to do is set the FormulaRowSourceIndex to either RowIndex or ListIndex.
By default, formulas are based on the VisualIndex of the rows. Usually, this doesn't matter, since you don't often use formulas that rely on the relative indices of rows. And such is the case with your sample - you aren't using any row indices in your formulas. The reason the AddRow isn't calculating is because it's Index is -1, and the CalcManager things it's an invalid row.
By switching the index to use RowIndex, both the summary and the cell in the AddNew row calculated immediately. You still need to set DeferredCalculationsEnabled to false, but as I mentioned above, that doesn't really matter since you have a summary that forces the calculation of every row, anyway.
So in your sample, I just added this line of code to the Form_Load
Me.UltraGrid1.DisplayLayout.Override.FormulaRowIndexSource = FormulaRowIndexSource.RowIndex
Mike, I can confirm that we now have a working solution and once again thanks for your time on this.
Cheers