Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2325
force updating column formulas
posted

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.  I have attached a zip file containing the form.

thanks

TestCostSummExample.zip