Tree view scripts

The Properties window allows you to attach the following scripts to a tree view field: pre script, select script, post script, collapse script, expand script and double-click script.

Pre script

The pre script runs when the focus moves to the tree view field from another location.

Select script

The select script runs each time a different node is selected in the tree view field.

Post script

The post script runs when the focus leaves the tree view field.

Expand script

The expand script runs each time a parent node is expanded in the tree view field. Use this script to add child nodes when a parent node is expanded. Use the TreeView_GetExpandingNode() function to retrieve the ID of the node being expanded.

The following example is the expand script for the Address List tree view field. It adds child nodes containing customer information to the node being expanded.

local long node_ID;
local long new_node;
local string node_label;

{Get the ID of the expanding node.}
node_ID = TreeView_GetExpandingNode('Address List');
{Get the label for the node.}
node_label = TreeView_GetNodeLabel('Address List', node_ID);

{Set the appropriate range for the Customer_Data table.}
range clear table Customer_Data;
set 'Region' of table Customer_Data to node_label;
range start table Customer_Data by key 3;
range end table Customer_Data by key 3;

{Read the customer records for the region.}
get first table Customer_Data;
while err() <> EOF do
	{Add the new node with customer information. Use the index card
	image (image 3).}
	new_node = TreeView_AddNode('Address List', 'Customer Name' of table Customer_Data, 0, node_ID, false, 3, 3);
	get next table Customer_Data;
end while;

Collapse script

The collapse script runs each time a parent node is collapsed in the tree view field. Use this script to remove child nodes from the node being collapsed. Removing the non-visible nodes allows the tree view field to operate more efficiently and be more responsive. Use the TreeView_GetCollapsingNode() function to retrieve the ID of the node being collapsed.

The following example is the collapse script for the Address List tree view field. It removes the child nodes from the node being collapsed.

local long node_ID;
local long number_removed;

{Get the ID of the collapsing node.}
node_ID = TreeView_GetCollapsingNode('Address List');
{Remove the children from the node.}
number_removed = TreeView_RemoveChildren('Address List', node_ID);

State click script

The state click script runs each time the user clicks the state image for a node. Clicking the state image for an item does not change the selection. Use the TreeView_GetClickNode() function to retrieve the node ID of the node whose state image was clicked.

The following example is the state click script for the Address List tree view field. It toggles the state image displayed when the state image is clicked.

local long click_node;
local integer previous_image;

{Find which node's state image was clicked.}
click_node = TreeView_GetClickNode('Address List');

if TreeView_GetNodeStateImage('Address List', click_node) = 1 then
	{The clicked item is shown. Show the unclicked item.}
	previous_image = TreeView_SetNodeStateImage('Address List', click_node, 2);
else
	{The unclicked item is shown. Show the clicked item.}
	previous_image = TreeView_SetNodeStateImage('Address List', click_node, 1);
end if;

Double-click script

The double-click script runs each time a node is double-clicked. If a node contains children, the node will be expanded or collapsed and the expand or collapse script will run. Then the double-click script will run. Use the TreeView_GetSelectedNode() function to retrieve the node ID of the node that was double-clicked.

Context menu script

The context menu script runs when the tree view control is right-clicked. It is used for context menus. Refer to Context Menus for more information.


Documentation Feedback