Reputation: 1161
I use a numeric updown control to allow the users to adjust numeric values to effect a change in my ultragrid. In my ultragrid InitializeLayout event I have the following:
...
var band = e.Layout.Bands[0];
band.Columns["CalcMarkup"].Formula = "if ([Markup] > 0, [FinalCost]*([Markup]/100), 0)";
band.Columns["RemainingCost"].Formula = "if([CalcMarkup] > 0, 0, [FinalCost] )";
band.Columns["ForcedMarkup"].Formula = "if([RemainingCost] = 0, 0, ([RemainingCost]/[sumRemCost()])*[force()])";
...
grdMain.DisplayLayout.Bands[0].Summaries.Add("force", "[ForcedAdj()]", SummaryPosition.UseSummaryPositionColumn, grdMain.DisplayLayout.Bands[0].Columns["ForcedMarkup"]);
...
var value = 1 - (nudMarginPer.Value/100);
_marginFormula = string.Format("( ( ([finCost()]/{0})-sum([FinalCost]) )-sum([CalcMarkup])-5000000 )", "{0}");
band.Summaries.Add("ForcedAdj", string.Format(_marginFormula, value));
band.Summaries["ForcedAdj"].SummaryDisplayArea = SummaryDisplayAreas.None;
...
grdMain.DisplayLayout.Bands[0].Summaries.Add("force", "[ForcedAdj()]", SummaryPosition.UseSummaryPositionColumn, grdMain.DisplayLayout.Bands[0].Columns["ForcedMarkup"]);
in the numeric updown event:
void nudMarginPer_ValueChanged(object sender, EventArgs e)
{
var value = 1 - (nudMarginPer.Value/100);
grdMain.DisplayLayout.Bands[0].Summaries["ForcedAdj"].Formula = string.Format(_marginFormula, value);
}
This works well in that when the user presses the updown buttons the summary (ForceAdj) values change and is reflected in the grid summary row. However the column formula for ForcedMarkup doesnt change until a second button press. So now the summary is correct however the value in the cell is off.
My question is this... How do I force the formula for ForcedMarkup (or any column formula) to refresh to reflect the current calcs?
I have tried forcing a grid update, calcmanager recalc, etc... nothing seems to work.
*** 7/20: This appears to be an issue when using group by.
Upvotes: 0
Views: 3090
Reputation: 31
From my experience, it could be calcmanager's trick.
Calcmanager recalc() method forces recalculation only for dirtied formulas, so you should dirty them first.
Also, if DeferredCalculationsEnabled property is set to true, calcmanager may defer recalculation until formula cells (or whole grid) becomes visible.
That's what worked for me :
1. If datagrid is not visdible yet e.g trying to get values of calculated columns/summaries while still in form constructor
calcmanager_instance.DeferredCalculationsEnabled = false;
calcmanager_instance.ReCalc();
2.If datagrid is already visible, but formulas need to be recalculated
calcmanager_instance.DirtyAllFormulas();
calcmanager_instance.ReCalc();
In general, this combination should unconditionally and instantly force recalculation of all formulas :
calcmanager_instance.DeferredCalculationsEnabled = false;
calcmanager_instance.DirtyAllFormulas();
calcmanager_instance.ReCalc();
I think, there must be a way to dirty only selected formulas, but I didn't look for it.
Upvotes: 3