I set a bunch of named references in my code which the user can then use in formulas through the formula builder. Some of the calculations involve dividing by that value, which can be 0. Instead of forcing the users to test if that value is 0 when dividing by it is there a way to catch this error?
None of the events of the UltraCalcManager fire but there is a OverflowException thrown when setting the formula property of the column. I set the FormulaErrorValue of the column but I still receive the exception. How can I prevent this from occurring?
Hi,
I'm not sure what you mean. If a formula results in a division by 0 error, there should not be an exception. The cell will simply show error code like "#DIV0".
If you are getting an exception, then something is wrong. Either the exception is occurring in your code or it's a bug in the grid or the calc manager.
Are you sure this is not just a first chance exception that is being caught?
I'm positive its not a first chance exception. I bind the grid and then add custom columns created by the user to the grid. Here is a code snippet:
//formulaColumn is an UltraGridColumn
//column is a custom object. column.SystemType is System.Decimal
//column.Formula is [Long] / [//NAV] Long is a bound column and NAV is a named reference with a value of 0.
formulaColumn.DataType = column.SystemType;try{ formulaColumn.FormulaErrorValue = 0; formulaColumn.Formula = column.Formula;}catch (OverflowException ex)
{
//exception occurs here and I have to set formulaColumn.Formula ="0" to continue
}
I am not sure why that's happening. Maybe something else in the code is using the Value of the cell for some calculation in code?
If not, then you should see if you can duplicate this in a small sample project and Submit an incident to Infragistics Developer Support so they can take a look. A formula calculation should never result in an exception.
The only way to do that would be to use a CreationFilter or DrawFilter. I'd go with the CreationFilter, myself. You can trap for whatever UIElement in the grid is drawing the summary text and just set the Text property on the element.
I recommend that you get the Infragistics UIElementViewer Utility. It will be a big help in determining which element(s) to look for.
I have the event fire correctly when a division by zero occurs, but I cannot suppress the #DIV/0! message that is now showing in the summary.
Is there any way of making sure this message is not shown? As far as I can see while debugging is that the message is the result of e.ErrorInfo.Code.
Problem is, everywhere I find this code during debugging is a read only property, so I can't change it.
I would simply like to replace the #DIV/0! message with an empty string or something like "-". How can I accomplish this?
Hm, sorry about that, I made a bad assumptoin and I was totally wrong on that one.
I just tested it out with your code and I get the same results. The event does not fire. This looks like a bug to me. You should Submit an incident to Infragistics Developer Support so they can check it out and get it corrected.
This is pulled directly from the helpfile for FormulaCalculationError. It makes it appear quite plainly that division by zero should fire this event.
using Infragistics.CalcEngine;using Infragistics.Win.UltraWinCalcManager;private void ultraCalcManager1_FormulaCalculationError(object sender, Infragistics.CalcEngine.FormulaCalculationErrorEventArgs e) { switch ( e.ErrorInfo.Code ) { case UltraCalcErrorCode.Div: //e.ErrorDisplayIcon = errorIconDivideByZero; e.ErrorDisplayText = "Divide by Zero Error"; e.ErrorValue = "#Div"; break; case UltraCalcErrorCode.NA: //e.ErrorDisplayIcon = errorIconNA; e.ErrorDisplayText = "A formula of NA was encountered"; e.ErrorValue = "#NA"; break; case UltraCalcErrorCode.Num: //e.ErrorDisplayIcon = errorIconInvalidNumericValue; e.ErrorDisplayText = "Invalid numeric values encountered"; e.ErrorValue = "#Num"; break; case UltraCalcErrorCode.Value: //e.ErrorDisplayIcon = errorIconInvalidArgument; e.ErrorDisplayText = "Invalid argument type encountered"; e.ErrorValue = "#Value"; break; } }
The FormulaCalculationError event fires when there is something the CalcManager cannot handle like a circularity. A division by 0 is not a FormulaCalculation error. The formula in this case is calculated just fine - it just that the result is an error code.