We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

# How to calculate formula using ComputeFormulaValueAt method in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: January 3, 2016 |
Last Revised Date: February 13, 2020
Tags:

## Calculate formula using ComputeFormulaValueAt method

By default, the arithmetic operations cannot be parsed in Expression fields. It can be achieved by defined the methods manually like SUM,MUL,SUB… and adding those methods to the library function. So that we can use these methods to perform the arithmetic operations. By this way, any of the methods can be added for customization to calculate the values.

C#

```ExpressionFieldEvaluator fieldEval;
fieldEval = this.gridGroupingControl1.TableDescriptor.ExpressionFieldEvaluator;

//Method for sum operation
private string Sum(string argument)
{
string[] arg = argument.Split(',');
int result = 0;
foreach (string str in arg)
{
result += Convert.ToInt16(str);
}
return result.ToString();
}

//Expression for compute the formula
MessageBox.Show(fieldEval.ComputeFormulaValueAt(((IExpressionFieldEvaluator)fieldEval).Parse(this.textBox1.Text, true)));
```

VB

```Dim fieldEval as ExpressionFieldEvaluator
fieldEval = Me.gridGroupingControl1.TableDescriptor.ExpressionFieldEvaluator;

'Method for sum operation
Private Function Sum(ByVal argument As String) As String
Dim arg() As String = argument.Split(","c)
Dim result As Integer = 0
For Each str As String In arg
result += Convert.ToInt16(str)
Next str
Return result.ToString()
End Function

'Expression for compute the formula
MessageBox.Show(fieldEval.ComputeFormulaValueAt((CType(fieldEval, IExpressionFieldEvaluator)).Parse(Me.textBox1.Text, True)))
```

ScreenShot

Samples:

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.