UIControllerDeltaOf Method

Returns The delta between the value of expression before the EnterRow event, and the current value of expression


Namespace: Firefly.Box
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
public Number DeltaOf(
	Func<Number> expression


expression  FuncNumber

Return Value

The method returns The delta between the value of expression before the EnterRow event, and the current value of expression


Useful for maintaining a grand total in a form


How to use DeltaOf to maintain a grand total
This example is based on test data. The code for the entities included in this test data can be found in the documentation of Entity
This example uses automatic tools to generate parts of the user interface. Those tools can be found in the example of the documentation of Form
using Firefly.Box;
using Firefly.Box.Data;
using Firefly.Box.UI;

namespace TestFirefly.Box.Documentation
    public class JobsTotal
        public void ShowJobs()
            var jobs = new Pubs.Jobs();

            var totalMinLevel = new NumberColumn();
            var countJobs = new NumberColumn();
            //Calculate the total before running the task
            var bp = new BusinessProcess { From = jobs };
            bp.ForEachRow(() =>
                totalMinLevel.Value += jobs.MinLevel;

            //Create the total textbox 
            var totalTextBox = new TextBox
                Data = totalMinLevel,
                AllowFocus = false
            //Position the textbox below the grid

            //Create a label
            var totalLabel = new Label
                Text = "Total Min Level"

            var countTextBox = new TextBox
                Data = countJobs,
                AllowFocus = false

            var countLabel = new Label { Text = "Number of jobs" };

            //Create the UIController
            var uic = new UIController
                From = jobs,
                View = UITools.GenerateFormWithGridFor(
                    "DeltaOf demo",
                    "Change the value of Min Level, and leave the row to see the affect on the totals.\n" +
                    "Try also deleting rows (using F3) and creating new ones."
                    , jobs.Id
                    , jobs.Description
                    , jobs.MinLevel)
            UITools.AddControlsToForm(uic.View, countLabel, countTextBox, totalLabel, totalTextBox);

            var insertB = new Button { Text = "Insert New Row", Width = 150 };
            insertB.Click += (sender, e) => e.Raise(Command.InsertRow);

            var deleteB = new Button { Text = "Delete Row", Width = 100 };
            deleteB.Click += (sender, e) => e.Raise(Command.DeleteRow);
            UITools.AddControlsToForm(uic.View, insertB, deleteB);

            //Add all the jobs columns to the Columns Collection
            //Add the total columns to the columns collection
            uic.Columns.Add(totalMinLevel, countJobs);

            uic.SavingRow += ( b) => //When the row is left, update the total with the delta in the MinLevel
                totalMinLevel.AddDeltaOf(() => jobs.MinLevel);
                countJobs.AddDeltaOf(() => 1);


See Also