CalcEngine formulaEngine;
CustoCalulate calc = new CustoCalulate(this.gridControl1);
formulaEngine = new CalcEngine(calc);
public class CustoCalulate : ICalcData
{
GridControl grid;
public CustoCalulate(GridControl _grid)
{
grid = _grid;
}
public event ValueChangedEventHandler ValueChanged;
public object GetValueRowCol(int row, int col)
{
return grid[row, col].CellValue;
}
public void SetValueRowCol(object value, int row, int col)
{
grid[row, col].FormattedText = value.ToString();
}
public void WireParentObject()
{
}
} |
this.gridControl1.CurrentCellEditingComplete += GridControl1_CurrentCellEditingComplete;
this.gridControl1.CurrentCellInitializeControlText += GridControl1_CurrentCellInitializeControlText;
private void GridControl1_CurrentCellInitializeControlText(object sender,GridCurrentCellInitializeControlTextEventArgs e)
{
if(e.Style.CellType.Equals(GridCellTypeName.FormulaCell) && e.Style.Tag != null)
{
e.ControlText = e.Style.Tag.ToString();
}
}
private void GridControl1_CurrentCellEditingComplete(object sender, EventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
GridStyleInfo style = this.gridControl1[cc.RowIndex, cc.ColIndex];
if (style != null && style.CellType.Equals(GridCellTypeName.FormulaCell))
{
//To compute the array formula
if (style.Text.StartsWith("{=") && style.Text.EndsWith("}"))
{
style.Tag= style.CellValue;
style.FormattedText = formulaEngine.ParseAndComputeFormula(style.Text);
}
}
} |