


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