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?
Here is the entire code for the small app:
DataTable table = new DataTable(); table.Columns.Add("Name", typeof(String)); table.Columns.Add("Value", typeof(double)); ultraCalcManager.NamedReferences.Add("NAV", "0"); DataRow row = table.NewRow(); row["Name"] = "John"; row["Value"] = 5; table.Rows.Add(row); ultraGrid1.DataSource = table;
and in initialize layout:
UltraGridColumn column = ultraGrid1.DisplayLayout.Bands[0].Columns.Add("Formula"); column.DataType = typeof(double); column.Formula = "[Value] / [//NAV]"; column.FormulaErrorValue = 0;
I hooked up all of the Error events of the UltraCalcManager but I'm just expecting FormulaCalculationError to fire but it does not.
Which events are you referring to and when are they not fired?
OK, so I realize now that FormulaErrorValue doesn't specify the text to display in the cell, merely the formula to pass along to the data source. But why are none of the UltraCalcManager events being fired?
I created a small demo project and wasn't able to reproduce it like I had expected. I create a data table with 2 columns, name(string) and value(double). I add a row to the table and bind the grid to this. I add a named reference with a formula of "0" and create a column of data type double with formula = "[value] / [//reference]" and infinity is displayed as cell text. I set the formula error value to 0 but still see infinity. Also, no error events of the UltraCalcManager are fired. Shouldn't the cell text become 0 and shouldn't some events be firing to let me know that I am attempting to divide by zero?
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.