Hi Josip,
Thanks for your interests in Syncfusion products.
By default, Decimal return type does not support the infinity results. To overcome this issue, set the return type as Double for the ExpressionFieldDescriptor. Already we have provided the KB for this scenario. Please make use of below link,
Note
If you want to return any message in ExpressionField instead of returning “0” or “infinity”, Custom method can be used to customize the Formula for ExpressionField. Please make use of below code and sample,
Code snippet
Custom method
//DividedValue that returns DivideByZero if any of the argument value is zero else returns divided value
private string DividedValue(string args)
{
// Get the list delimiter (for en-us, it is a comma).
char comma = Convert.ToChar(this.gridGroupingControl1.Culture.TextInfo.ListSeparator);
string[] arguments = args.Split(comma);
decimal arg1, arg2;
if (decimal.TryParse(arguments[0], System.Globalization.NumberStyles.Any, null, out arg1)
&& decimal.TryParse(arguments[1], System.Globalization.NumberStyles.Any, null, out arg2))
{
//returns DivideByZero if any of the column value is zero
if (arg1 == 0 || arg2 == 0)
{
return "DivideByZero";
}
else
return Math.Abs(arg1 / arg2).ToString();
}
return "Invalid input";
}
|
Adding the custom method to Grid
//Adding Custom function to Expression Field
this.gridGroupingControl1.TableDescriptor.ExpressionFieldEvaluator.AddFunction("Divide", new ExpressionFieldEvaluator.LibraryFunction(DividedValue));
// Adding the Expressions using DividedValue function.
ExpressionFieldDescriptor expField = new ExpressionFieldDescriptor("Divide", "Divide([CategoryName],[CategoryID])", typeof(System.String));
//Adding the custom ExpressionField to Grid
this.gridGroupingControl1.TableDescriptor.ExpressionFields.Add(expField); |
Screenshot
Regards,
Arulpriya