Please enable JavaScript to view this site.

A-Shell Reference

When adding items to an existing tree control, care should be taken about the array index numbers. For example, if you initially load a tree control with a ten item array, then append another ten item array to it, the control will know that the second set of ten items should be internally numbered eleven to twenty, but it will be up to your program to realize that item fifteen is really the fifth item of the second set of ten loaded. One way to avoid this confusion is to maintain a single array which matches the contents of the tree control, even if you did not load them all at once. In the example just cited, rather than passing two separate arrays (or worse, overwriting the original array with the second set of items), it might be better to map an array large enough for all the items, and then just add to it as you add to the tree control. The trick here is to specify the appropriate starting array index, rather than (1). For example:

MAP1 ARRAY(50),S,100

 

FOR I = 1 TO 8

ARRAY(I) = <data>

NEXT I

! now create the control with the first 8 items...

XTR_OPCODE = 0  ! (create)

FLAGS = XTF_MODELESS + XTF_NOSEL

ADDCNT = 8

xcall XTREE, SROW, SCOL, ANSWER, ARRAY(1), ADDCNT, COLDEF, EXITCODE, &

   EROW, ECOL, FLAGS, "", MMOCLR, XTRCTL

 

! now load up an additional 12 items, adding them first to array

FOR I = 9 TO 20

ARRAY(I) = <data>

NEXT I

! append these items to the existing tree control...

XTR_OPCODE = 2  ! (append)

ADDCNT = 12

! note that we pass ARRAY(9) rather than ARRAY(1) ...

xcall XTREE, SROW, SCOL, ANSWER, ARRAY(9), ADDCNT, COLDEF, EXITCODE, &

   EROW, ECOL, FLAGS, "", MMOCLR, XTRCTL

ADDCNT = ADDCNT + ADDCNT

 

Now the 20 items in our local copy of ARRAY() match up with the contents of the tree control, so that when we receive a selected item number via the ANSWER parameter, we can reference the corresponding item in our local array directly, as ARRAY(ANSWER).

The initial selection(s) are determined (by the answer parameter) in the same way as when creating a new list, except that if you do not specify an initial selection, the default will be the first item appended. If you do specify one or more selections in the answer parameter, they re interpreted relative to the combined list after appending, not relative to the just the appended items. That is, setting answer=2 will select the second row in the table, not the second row appended.