Hello is there any way I can validate my formula before attaching it on a grids column?
I want to prevent unhandled for CalcManager situations like "Integer + String" or "String + String" instead of using concatenation.
I tried to use CompileFormula but I caught only SyntaxErrors.
Any Idea?
The samples are installed with the product (optionally) when you install. So they should be on your hard drive if you chose to install them when you installed the product. If they are not there, then you might need to run the installer again and get opt-in to get them.
If you installed the samples, they will be under your install folder in a folder something like this:
..\WinForms\2018.1\Samples\Legacy\CalcManager\CS\UserDefinedLibrary.CS
Hello Mike,
Thanks for your response.
So there is now way of preventing errors right now?
Can you share the link of UserDefinedLibrary sample?
I cannot find it.
Thanks
I took another look, just to see if I could provide you with a sample of overriding the "+" operator, but it looks like I was mistaken. You can override the named functions, but apparently, it is not possible to override the unary operators like "+'. Sorry for the confusion.
Hi Adamantidis,
There really isn't any way to do what you are asking for here. When dealing with formulas there are basically two steps. The first is compiling the formula. That's where the CalcManager will detect things like syntax errors. But in the case of a formula like:
"a" + "a"
there is no syntax error. The syntax here is correct, it's just that the arguments are of the wrong type. That type of error doesn't get detected until the second phase, which is calculation.
So this returns an UltraCalcValueError as the result of the formula.
Of course, if you are writing formulas in your application, this shouldn't be a problem, because you could detect this and fix it, so presumably, you are allowing your users to create custom formulas and plug them into the grid? In that case, there's really only two things I can think of that might help:
1) Write your own custom functions that are more forgiving of errors. There's a sample (UserDefinedLibrary) which demonstrates how to do this. You can add your own functions to the calc engine or override existing ones (by registering a custom function with the same name as an existing one). You could then handle the code that performs the calculation yourself and so you could override the addition function and have it check for strings and then call the ConCat function if any of the arguments are strings. Of course, you would have to do this for every possible function and depending on how far you wanted to go with it, it could be a pretty massive undertaking.
2) Educate your users about the difference between '+' and Concat functions. This might not be as bad as it seems, since the CalcManager is based on Excel and Excel does the same thing - it displays an error if you try to use the '+' operator on two strings.
Hello,
Thanks for your response, however your answer does not help me.
First of all I am working on Infragistics Ultragrid now, so I am not able to use calcSettings.
I override and tried to catch all the bellows event (FormulaCalculationError, FormulaReferenceError, FormulaSyntaxError).
Only FormulaSyntaxError were triggered correctly.
All the other were not being triggered and when I was applying the formula instead of result I had columns with "#XXX".