List view scripts

The Properties window allows you to attach the following scripts to a list view field: pre script, post script, selection changed script, double-click script and state click script.

Pre script

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

Post script

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

Item changed script

The item changed script runs any time an item is added to or removed from the selection. Be aware that when the mouse is used to select several items, this script runs as items are included or excluded from the selection rectangle.

[spacer]

The following example is the item changed script for the Explorer List list view field. It updates the Object Count field with the number of items selected in the list view.

local long selection_count;

{The selection changed. Update the count of the objects selected.}
selection_count = ListView_SelectionCount('Explorer List');

if selection_count > 0 then
	{Indicate how many objects are selected.}
	'(L) Object Count' = str(selection_count) + " object(s) selected";
else
	{Display the total number of objects in the list.}
	'(L) Object Count' = str(ListView_ItemCount('Explorer List')) + " object(s)";
end if;

Selection changed script

The selection changed script runs one time after the selection in the list view has changed. The script runs once, regardless of the number of items that were added to or removed from the selection.

Double-click script

The double-click script runs each time an item is double-clicked. Double-clicking an item will change the selection, so the selection changed script will run prior to the double-click script. Use the ListView_GetClickItem() function to retrieve the index of the item that was double-clicked.

State click script

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

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

local long click_item;
local integer previous_image;

{Find which item's state image was clicked.}
click_item = ListView_GetClickItem('Explorer List');

if ListView_ItemGetStateImage('Explorer List', click_item) = 1 then
	{The clicked item is shown. Show the unclicked item.}
	previous_image = ListView_ItemSetStateImage('Explorer List', click_item, 2);
else
	{The unclicked item is shown. Show the clicked item.}
	previous_image = ListView_ItemSetStateImage('Explorer List', click_item, 1);
end if;

Context menu script

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


Documentation Feedback