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. Image for the cookie policy date

cannot understand formula

Hi, Could you please help with the formula problem?: I cannot understand the meaning of this line of code in grid sample: e.Style.Text = string.Format("=({0}{1} + {2}{1})", GridRangeInfo.GetAlphaLabel(1), GridRangeInfo.GetNumericLabel(e.RowIndex),GridRangeInfo.GetAlphaLabel(2)); I need to get sum of cells from G to M. Also I do not want to display to user the string “=G1+H1+…” when he click on cell. Actually I need to have that formula cell ReadOnly Thanks in advance

1 Reply

AD Administrator Syncfusion Team July 13, 2004 05:26 AM UTC

The method, string.Format, returns a string. The first argument for string.Format is a string that defines what the returned string should be. In this first argument, {x} where x in an integer, defines tokens that represent the values from the other items in the string.Format arguement list. So, {0} represents the value of the second argument in the string.Format argument list, {1} is the 3rd argument, and so on. GridRangeInfo.GetAlphaLabel is a function that accepts an integer and returns the corresponding letter of the alphabet that normally serves as the column header text for the particular column. So, GridRangeInfo.GetAlphaLabel(1) is "A", GridRangeInfo.GetAlphaLabel(2) is "B", and so on. The other method does the same except it returns a number that normally serves an teh row header text, "1", "2" etc. One way to prevent the formula from displaying is to handle the CurrentCellStartEditing event and cancel it if it is a formula cell you don''t want to edit.
private void gridControl1_CurrentCellStartEditing(object sender, CancelEventArgs e)
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(this.gridControl1[cc.RowIndex, cc.ColIndex].CellType == "FormulaCell")
		e.Cancel = true;

Live Chat Icon For mobile
Up arrow icon