Click or drag to resize

GridRow Equation

The following code snippet can be used to set the 4th control in a grid row equal to the sum of the first 3 controls in the same row.

Complete theses steps to add this functionality to your application.

  • Add the following GridRowEquation code snippet to your application's screen script.
  • Add a Grid control to the screen.
  • Add 4 value boxes to the first grid row (or other controls with a "Value" property of type TVQ).
  • In the first grid row, set the OnEndValueChange property of controls 1, 2, and 3 to execute the GridRowEquation delegate we just added to the screen script. By setting the OnEndValueChange of the first 3 controls, we ensure that our calculation will run when any of the values used in the equation are updated. Control 4 will be receiving the result.
  • Modify the equation to perform the desired calculation.
C#
// IMPORTANT: for use with OnEndValueChange of each control used in the equation
public void GridRowEquation(object sender, TagSubscriptionArgs subscription, TVQ tvq)
{
    IControlParent parent = (sender as ControlBase).Parent;

    // get values of first 3 controls in grid row
    TVQ tvq1 = ControlBase.GetProperty<TVQ>(parent.Children[0], "Value");
    TVQ tvq2 = ControlBase.GetProperty<TVQ>(parent.Children[1], "Value");
    TVQ tvq3 = ControlBase.GetProperty<TVQ>(parent.Children[2], "Value");

    // calculate sum of values
    double sumValue =
        (tvq1?.ValueToDouble() ?? 0) +
        (tvq2?.ValueToDouble() ?? 0) +
        (tvq3?.ValueToDouble() ?? 0);
    TVQ sumTVQ = new TVQ(DateTime.Now, sumValue, 192);

    // update 4th control in grid row with result
    ControlBase.SetProperty(parent.Children[3], "Value", sumTVQ);
}