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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

My formulas do not "adjust" when I drag columns

Thread ID:





73214 Apr 24,2008 05:50 PM UTC May 2,2008 01:05 PM UTC WinForms 1
Tags: GridControl
Asked On April 24, 2008 05:50 PM UTC

Is this expected behavior?

If I have a formula in A5 saying "=B5", and I drag B column in front of A column, shouldn't the formula update to "=A5" (since it is not the B column)?

I have the cell with the formula marked as "Enabled=false" if that matters because I do not want someone to click on the cell and change the formula.


Administrator [Syncfusion]
Replied On May 2, 2008 01:05 PM UTC

Hi Paul,

Thanks for the interest in Syncfusion products.

In a GridControl using DragColumnHeader, the column is removed from one location and inserted in another location, all in one operation. There is no property setting that automatically manages updating the references during this one step move operation.However you could subscribe to the ColsMoved event and update the formulas programmatically. Please refer the code snippet below that shows how we can update the formulas programmatically.

void gridControl1_ColsMoved(object sender, GridRangeMovedEventArgs e)
int from = e.From;
int to = e.Target;
char[] oldColumns = new char[gridControl1.ColCount + 1];
char[] newColumns = new char[gridControl1.ColCount + 1];

for (int i = 1; i < gridControl1.ColCount + 1; i++)
oldColumns[i] = Convert.ToChar(i + 64);

if (from != to)
#region finding the modified references for the columns
if (from > to)
char temp = newColumns[to];
for (int i = to; i < from; i++)
newColumns[i] = newColumns[i + 1];
newColumns[from] = temp;
else if (from < to)
char temp = newColumns[to - 1];
for (int i = to - 1; i > from; i--)
newColumns[i] = newColumns[i - 1];
newColumns[from] = newColumns[to];
newColumns[to] = temp;
#region Updating the formula
for (int row = 1; row <= gridControl1.RowCount; row++)
for (int col = 1; col <= gridControl1.ColCount; col++)
GridStyleInfo style = gridControl1[row, col];
if (style.CellType == GridCellTypeName.FormulaCell)
GridFormulaTag ftag = style.FormulaTag;
if (ftag != null)
string formula = style.CellValue.ToString();
char[] characters = formula.ToCharArray();

MatchCollection mc = Regex.Matches(formula, @"(\w\d)");
foreach (Match m in mc)
int index = Array.IndexOf(oldColumns, m.Value[0]);
if (index > 0)
characters[m.Index] = newColumns[index];
string newFormula = new string(characters);
if (formula != newFormula)
style.FormulaTag = null;
style.CellValue = newFormula;
#region Recalculating all the formula cells
GridFormulaCellModel model = gridControl1.CellModels["FormulaCell"] as GridFormulaCellModel;
GridFormulaEngine engine = model.Engine;

Please refer the sample in the below link that illustrates the above.


Please let me know if this is not what you needed.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon