I have written an application that allows my users to apply an unbound column to the grid. Then using formula builder dialogue apply a formula to perform thier own calculations in the grid on existing data. When they try to add a summary it will only allow count, max and min. I am assuming this is because when adding the unbound column for the formula I am letting the grid decide the data type to use (found this trick in another post that described a unhandled exception scenario in the calc engine). If I assign the data type (System.Double) everything works fine. Summaries work everything seems great until you try to apply a formula in that column that manipulates string data and returns a string. There is an unhandled exception somewhere in the calc engine that kills the application as per the first article I found that told me about the trick how to not get the unhandled exception. Typical setup of the code is as follows:
calcMan.SuspendCalc();
CreateColumnReturn newColumn = CreateFormulaColumn();
if (newColumn.Created)
{
gridQueryData.CalcManager = calcMan;
ShowFormulaBuilderDialog(newColumn.NewColumn);
}
calcMan.ResumeCalc();
Hi,
Well... if you have a column in the grid whose DataType is double, you cannot have a formula in that column that returns a string - the value of the cell must be a double.
It probably should not be crashing the application with an unhandled exception, but there's no way this can work the way you want it to.
If the field is a double and you need to calculate a numeric summary, then why is the formula returning a string? Is this just an error on the part of the user?
Absolutely! I was doing a "what if" scenario knowing what users will do sometimes. Is there a way to examine the possible outcome of the formula before turning on the calcmanager again? Maybe I can intercept this and remove the formula or repop the editor with a message about invalid formula for column type. I was trying to catch any exception thrown by calmanager but none of the provided exceptions I have found as well as a generic exception catch block will handle this error.
I tend to agree with you there. The result should probably be to return the error code rather than raising an exception.
Thanks Mike,
I created a case with developer support. The grid should at least provide a trappable error in the event the user just does not understand what they are doing. Thanks for your feed back!
Hi Lewis,
No, there's no way for you to trap what Type the results of a formula might be. Or at least no reasonable way. You might examine the formula and try to figure it out yourself in code, but that's really not feasible.
I guess one thing you might be able to do is use a DataFilter. A DataFilter on the grid column's Editor will theoretically allow you to intercept the value from the CalcManager and examine it before it get to the grid. So if it's a string, you could change it to a 0 or a null or something that the column can handle. I say "theoretically" because I have not tried this out, but I think it should work.