Can someone tell me how I can use null values in named references with an UltraCalcManager? I've created a formula editor which uses data from our database (using named references). However, sometimes the data contains null values. In that case, I want to assign a default value in the formula. But I can't seem to get it working. Below is some example code.
const string formula = "IF( ISNULL( [test] ), 100, [test] )"; var ultraCalcManager1 = new UltraCalcManager(); ultraCalcManager1.NamedReferences.Add("test", "75"); var result = ultraCalcManager1.Calculate(formula); ultraCalcManager1.NamedReferences.Clear(); ultraCalcManager1.NamedReferences.Add("test", "null()"); result = ultraCalcManager1.Calculate(formula);
The first result is fine, but with the second result I get an error. I tried all sorts of different values for the null namedreference, like null without parentheses, or even without quotes. How can I accomplish this?
Thanks in advance!
Works great! Thanks Mike.
I tried this out and I am getting the same results. But the results I get are very strange.
If I tried this in the Form_Load event, I get the same results as you.
If I create an UltraCalcManager and place it on the form and then use a TextBox control for the formula result, it works fine.
Using a CalcManager that is on the form with the Calculate method does not work inside the Form_Load, but it works later on if I use a button_click event.
So I think the problem is that the code you have here is trying to perform operations on the CalcManager synchonrously. You are expecting that when you add a new NamedReference to the NamedReferences collection that the NamedReference is immediately available for use in a formula. But this is not the case, by default. It works okay when your formula is '75' because that's a literal value and requires no extra calculation. But "null()" is a function. I also tried the same thing using "sum(5, 5)" and got the same results, so it's not just null that is a problem, it's any function.
Anyway, if I am right, then the solution is simply this:
const string formula = "IF( ISNULL( [test] ), 100, [test] )"; var ultraCalcManager1 = new UltraCalcManager(); ultraCalcManager1.CalcFrequency = CalcFrequency.Synchronous; ultraCalcManager1.NamedReferences.Add("test", "75"); var result = ultraCalcManager1.Calculate(formula); ultraCalcManager1.NamedReferences.Clear(); ultraCalcManager1.NamedReferences.Add("test", "null()"); result = ultraCalcManager1.Calculate(formula);
I tried this out and it works fine for me.
Hello Torx,
I`m not sure that I understand well your scenario and requirements, but maybe one possible approach could be if you are using formula:
ultraGrid1.DisplayLayout.Bands[0].Columns["C"].Formula = "if([B]=null() , 0 , [B])";
Please take a look at the attached sample for more details. About NamedReferences, please take a look at:
http://help.infragistics.com/Help/NetAdvantage/WinForms/2013.1/CLR4.0/html/WinCalcManager_NamedReferences_Formula.html
http://help.infragistics.com/Help/NetAdvantage/WinForms/2012.2/CLR4.0/html/Win_WinCalcManager_Using_WinCalcManager.html
Another possible approach could be if you create your own custom formula. Please take a look at that forum thread: http://ko.infragistics.com.es/community/forums/t/80164.aspx?PageIndex=2 There you could find few samples.
Let me know if you have any qustions.
Regards