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
515
EnsureCalculated
posted

Hi,

I'm hoping that someone here can give me a sample of the usage of EnsureCalculated. I have a UltraGrid with numerous formulas and qute a few custom summaries. The problem I'm having is that the summaries are throwing exceptions because the values that they are meant to summarize have not been calculated in time. Currently, the CalcManager is set to Asynchronous. If I set it to Synchronous everything works fine, so it's obvious what the problem is. I could keep toggling the CalcFrequency property in code but that seems a bit silly.

Infragistics documentation states:

"By default, calculations are done Asynchronously on a timer. This ensures that the UI thread is not locked up when long or complex calculations are performed. The disadvantage to this mode is that a particular value may not be calculated when it is requested in code. When retrieving a calculated value using Asynchronous mode, you should call the EnsureCalculated method to ensure the value has been calculated."

There's very little discussion of EnsureCalculated in the documentation but what there is makes reference to a parameter of type IUltraCalcReference. My question is this: In the AggregateCustomSummary Method of a custom summary (derived from ICustomSummaryCalculator) how can i derive the IUltraCalcReference of the row being passed in as an argument so that I might use EnsureCalculated to make certain that the appropriate cells have been calculated?

any help would certainly be appreciated

Steve

Parents
  • 469350
    Suggested Answer
    Offline posted

    Hi Steve, 

    What kinds of things does your ICustomSummaryCalculator need? I assume you are referring to cells within a row of the grid?

    It's unusual to mix formula summaries with Custom summaries. You might be better off creating a new function and registering it in the CalcManager. That way, your calculations would be done as part of the Calc network, and they would get processed in order. There's a sample included in the NetAdvantage SDK (under the CalcManager samples which demonstrates how to create your own function library and register it with the CalcManager.

    If that's no good, then you will need to determine a way to get the IUltraCalcReference that represents the object you need calculated. Assuming this is an UltraGridCell, then I don't think the CalcReference for a cell is exposed in any obvious way. CalcReferences are deliberately hidden because for the most part, you should never have to deal with them directly. But what you can do is use a static method on the grid called GetReferenceFromContext. You can pass in an UltraGridCell and it will return the IUltraCalcReference for that cell.

    But you should be aware that EnsureCalculated doesn't go straight to the item you give it. What it essentially does it cause all calculations to be performed synchronously until the reference you gave it is calculated. It doesn't change the order of calculation, either. So it could lock up your UI thread while it's working, which is the same as setting the CalcFrequency to Synchronous. So you are really better off creating your own function and using that, rather than mixing formulas and custom summaries - if you can.

     

     

Reply Children