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);
}
oldColumns.CopyTo(newColumns,0);
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;
}
#endregion
gridControl1.BeginUpdate();
#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;
}
}
}
}
}
#endregion
#region Recalculating all the formula cells
GridFormulaCellModel model = gridControl1.CellModels["FormulaCell"] as GridFormulaCellModel;
GridFormulaEngine engine = model.Engine;
engine.RecalculateRange(GridRangeInfo.Table());
#endregion
gridControl1.EndUpdate();
gridControl1.Refresh();
}
}
Please refer the sample in the below link that illustrates the above.
http://websamples.syncfusion.com/samples/Grid.Windows/F73214/main.htmPlease let me know if this is not what you needed.
Regards,
Asem.