Hi Arda,
Thanks for using Syncfusion products.
We have created the simple sample with GridDataBoundGrid and in that sample , the first 3 column values are calculated and displayed it in 4th column as per your requirement. To create the dynamic formula , GridFormulaEngine can be used. In the attached sample, the cell values are calculated in CurrentCellKeyDown event when press the “enter” key. Please make use of the below code.
Code example:
this.gridDataBoundGrid1.CurrentCellKeyDown += new KeyEventHandler(gridDataBoundGrid1_CurrentCellKeyDown);
void gridDataBoundGrid1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
GridFormulaEngine engine = new GridFormulaEngine(this.gridDataBoundGrid1.Model);
List<MyMath> source = this.gridDataBoundGrid1.DataSource as List<MyMath>;
string cellText = this.gridDataBoundGrid1.CurrentCell.Renderer.ControlText;
int i = this.gridDataBoundGrid1.CurrentCell.RowIndex - 1;
double aValue = (double)source[i].A;
int bValue = (int)source[i].B;
double cValue = (double)source[i].C;
if (!string.IsNullOrEmpty(cellText))
{
string formula = cellText;
//Replacing the given expesson with values.
if (formula.Contains("a"))
formula = formula.Replace("a", aValue.ToString());
if (formula.Contains("b"))
formula = formula.Replace("b", bValue.ToString());
if (formula.Contains("c"))
formula = formula.Replace("c", cValue.ToString());
string result = engine.ComputeFormulaText(formula);
this.gridDataBoundGrid1.CurrentCell.Renderer.ControlText = result;
}
this.gridDataBoundGrid1.Refresh();
}
}
Sample link:
Regards,
Piruthiviraj