|
//Event triggering
this.gridControl1.QueryCellInfo += GridControl1_QueryCellInfo;
//Event customiation
private void GridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
//For only the integer columns
if (e.RowIndex > 0 && e.ColIndex > 0
&& e.Style.CellValueType == typeof(int) && e.RowIndex == gridControl1.RowCount)
{
//To set the CellType
e.Style.CellType = GridCellTypeName.FormulaCell;
//To add the formula for the cell.
e.Style.CellValue = "=SUM(" + GridRangeInfo.GetAlphaLabel(e.ColIndex) + "1:" +GridRangeInfo.GetAlphaLabel(e.ColIndex) + (gridControl1.RowCount - 1) + ")";
}
} |
|
private void formulaBtn_Click(object sender, EventArgs e)
{
//To get the Formula string.
string cellValue = this.gridControl1[rowIndex, colIndex].CellValue.ToString();
//To get the calculated value.
string ComputedValue = this.gridControl1[rowIndex, colIndex].FormattedText;
MessageBox.Show("Formula : " + cellValue + "\nComputedValue : " + ComputedValue);
} |