ContentsIndexPreviousNext

Adding child items on each expansion

The second approach is to add child items each time the parent expands, and then remove them when the parent collapses. The code for adding the items is slightly easier because you do not have to guard against adding multiple times. However, you have additional code to handle the removal of the child items. A typical event procedure for this approach looks like this:

TREE-VIEW-EVENT-1.

    EVALUATE EVENT-TYPE
      WHEN MSG-TV-EXPANDING
          IF EVENT-DATA-1 = TVFLAG-EXPAND
             PERFORM ADD-CHILDREN
          END-IF

      WHEN MSG-TV-EXPANDED
          IF EVENT-DATA-1 = TVFLAG-COLLAPSE
             MODIFY TV-1, ITEM-TO-EMPTY = EVENT-DATA-2
          END-IF


Note that it is important that you add the children in response to the MSG-TV-EXPANDING event, and remove them in response to the MSG-TV-EXPANDED event. Any other approach can confuse the control and produce odd results.