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
}