Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
15
Custom calculation function in XamDataGrid with two or more arguments
posted

Hi!

I have a huge problem with XamDataGrid and custom functions. I have followed these steps to create my functions:

- Create a class that inherits from Infragistics.Calculations.CustomCalculationFunctionBase because CustomCalculationFunction class only accepts delegates with doubles and I need strings and guids.

- In that inherited class I've created functions for one, two or three parameters given to the calculation function:

private Func<string, object> _functionAA;
private Func<Guid?, object> _functionBB;
private Func<string, Guid?, string, object> _functionCC;

- I've created another custom class to manage all the custom functions that I need to add to XamDataGrid. All the functions are registered the same way:

private void RegisterCustomFunction(string name, Func<string, Guid?, string, object> function)
{
    CustomCalculationFunction customCalculationFunction = new CustomCalculationFunction(name, function);
    CalculationManager.RegisterUserDefinedFunction(customCalculationFunction);
}

private object OnFunctionExecuted(string param1, Guid? param2, string param3)
{
    // TODO: Code goes here
}

Finally, in the XamDataGrid field definition, I add the formula in the CalculationSettings property:

FieldCalculationSettings calculationSettings = new FieldCalculationSettings();
calculationSettings.Formula = "myCustomFunction([field1], [field2])";
field.CalculationSettings = calculationSettings;

I've created custom functions with one string, one Guid? and both works without problem but when I add more than one parameter to the function I get an ArgumentOutOfRangeException caused because numberStack.Count is zero when is supposed to be more than one when the function reaches GetArgument function called by Evaluate function:

I've tried using the same parameters sending to other functions with only one parameter delegate and there is no exception. I've also using only parameters of the same type like the CustomCalculationFunction class does but the exception persists. I can't attach the project because is extremely hugue and depends on enormous database.

Thanks for the help!!

Parents
No Data
Reply Children
No Data