Tree Control Events

Description

In some situations, where the tree control will display a lot of data, and it would take a long time to compute all of the data to be shown in the tree control, it would be advantageous to delay populating the branches in the tree until the user actually opens that node.

That way, if the user never opens a particular node on a tree, there is no need to compute all of the branches for that node. Consider the following example:

paths = <<%str%
A\!event_A
B\!event_B
C\!event_C
%str%
ui_dlg_box("tree",<<%dlg%
[%X;S=BRL;D="\"%.40,10path^<paths]
|;
[.40path]|
%dlg%, <<%code%
if a_dlg_button = "event_a" then
    a_dlg_button = ""
    expanded_a = <<%str%
A\Item 1
A\Item 2
A\Item 3
%str%
    paths = stritran(paths,"A\!event_A",expanded_a)
    paths = word_change("1",paths,crlf())
    path = word(expanded_a,1,crlf())
end if
if a_dlg_button = "event_b" then
    a_dlg_button = ""
    expanded_b = <<%str%
B\Item 4
B\Item 5
B\Item 6
%str%
    paths = stritran(paths,"B\!event_b",expanded_b)
    paths = word_change("1",paths,crlf())
    path = word(expanded_b,1,crlf())
end if
if a_dlg_button = "event_c" then
    a_dlg_button = ""
    expanded_c = <<%str%
C\Item 7
C\Item 8
C\Item 9
%str%
    paths = stritran(paths,"C\!event_c",expanded_c)
    paths = word_change("1",paths,crlf())
    path = word(expanded_c,1,crlf())
end if
%code%)

When this script is executed, it displays the following dialog box. Tree Control Events:

images/XD_Tree Events 1.gif

In this script, the data initially shown by the tree control is the contents of the "paths" variable. Initially, this variable is set to:

A\!event_a
B\!event_b
C\!event_c

When the user open the "A" node the event, event_a executes, and the entry A\!event_a in the "paths" variable is replaced by the expanded entry for the "A" node.

The "\" in the data is the tree delimiter. This is specified in the Xdialog by the directive D="\" in the format string of the tree control.

After the user has opened "A" the paths variable looks like this:

A\Item 1
A\Item 2
A\Item 3
B\!event_b
C\!event_c
images/XD_Tree Events 2.gif

Limitations

Desktop applications only.

See Also