Using $result in the Tree Widget

In the tree widget, events are triggered when a user expands or collapses items in the Tree View, opens or closes items in the List View, or double-clicks items in either view. When this happens, both the detail and the valueChanged triggers are activated. When the detail trigger is activated, it automatically fills $result with values that contain information about the event or events that have just occurred. You can therefore use $result to find out which event was triggered and program the appropriate action in the detail or Value Changed triggers.

$result can contain the following values in this order:

View ; Action ; Value

where:

  • View is TREE | LIST
  • Action is:
    • EXPAND | COLLAPSE, if View is TREE
    • OPEN | CLOSE, if View is LIST
    • empty, if any item is double-clicked
  • Value is:
    • the value of the selected tree item (for EXPAND, COLLAPSE, and OPEN)
    • the value of the list item’s parent or previously selected list item (for CLOSE, and for EXPAND if the parent is not already expanded)

If the user double-clicks a root node named RootNode, the detail trigger is activated twice and fills $result with the following values:

TREE;;RootNode
TREE;EXPAND;RootNode

The following example extracts local variables from $result to get the values for Action and Value, then activates the appropriate operation.

;Detail trigger 
variables
    string ACTION
    string VALUE
    string ITEMVALREP
endvariables

   getitem ACTION,$result,2
   getitem VALUE,$result,3

   selectcase ACTION
      case "EXPAND"
         getitem $3,$PARENTSTRUCTURE$,-1
         if($3 = "?")
            activate "TRESERV".BLDORG(VALUE,ITEMVALREP)
            $fieldvalrep(TREFLD.DUM) = "0=;%%ITEMVALREP"
         endif
      case "OPEN"
         ...
      endselectcase
end; end trigger

Related Topics