Using DataWindow information to populate a TreeView

A useful implementation of the TreeView control is to populate it with information that you retrieve from a DataWindow. To do this your application must:

Because a TreeView can display different types of information at different levels, you will probably define additional DataWindows, one for each level. Those DataWindows usually refer to different but related tables. When an item is expanded, the item becomes a retrieval argument for getting child items.

Populating the first level

This example populates a TreeView with a list of composers. The second level of the TreeView displays music by each composer. In the database there are two tables: composer names and music titles (with composer name as a foreign key).

This example declares two DataStore instance variables for the window containing the TreeView control:

datastore ids_data, ids_info

This example uses the TreeView control’s Constructor event to:

Populating the second level

When the user expands a root level item, the ItemPopulate event occurs. This script for the event:

Destroying DataStore instances

When the window containing the TreeView control closes, this example destroys the DataStore instances:

//Close event for w_treeview
DESTROY ids_data
DESTROY ids_info