ContentsIndexPreviousNext

Adding child items once

The first approach is to add child items the first time the parent is expanded, and them leave them in the control. To code this, respond to the MSG-TV-EXPANDING message by seeing if there are any children of the parent item. If not, then add them at this point. A typical event procedure for this would look like this:

TREE-VIEW-EVENT-1.
    EVALUATE EVENT-TYPE
      WHEN MSG-TV-EXPANDING
          IF EVENT-DATA-1 = TVFLAG-EXPAND    |Item expanding
              MODIFY TV-1( EVENT-DATA-2 ),
                NEXT-ITEM = TVNI-CHILD GIVING ITEM-1
              IF ITEM-1 = NULL               |No children
                PERFORM ADD-CHILDREN
            END-IF
         END-IF
    END-EVALUATE

The paragraph ADD-CHILDREN would do the work needed to add the child items. In this example, EVENT-DATA-1 contains a flag that describes whether the parent item is being expanded or collapsed, and EVENT-DATA-2 contains the ID of the parent item. See the description of the event MSG-TV-EXPANDING for details.