List Box Screen

These examples show how you can retrieve and manipulate the contents of a list box control from a default List Boxes screen.

Example 1

To try this example, paste the following code onto the On Next event in between the else and the Screen.Next action. This event can be found on the Actions tab of the screen's properties.

-- Retrieve the table with all of the selected list box items.
tbSelected = DlgListBox.GetSelected(CTRL_LIST_BOX);

strSelectedLabels = "";

-- Loop through the table tbSelected and add the name and index of the selected item to a string.
for index, value in tbSelected do
    -- Get the properties of the selected listbox item, so you can retrieve its name.
    tbProperties = DlgListBox.GetItemProperties(CTRL_LIST_BOX, value);

    -- Add the name of the listbox item (tbProperties.Text) and its index to the string for outputting.
    strSelectedLabels = "Index: "..value.." - "..strSelectedLabels..tbProperties.Text.."\r\n";
end

-- Display the labels and indexes of all selected listbox items in a dialog message.
Dialog.Message("ListBox", "The following listbox items were selected:\r\n"..strSelectedLabels, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

This action script demonstrates how to retrieve the items that were selected in a list box, in this case, simply outputting its indexes and values as a dialog message when you click the Next button.

Example 2

This example requires you to paste code onto two different events on a new List Box screen.

To try this example, paste the following code onto the On Preload event of a List Box screen. This event can be found on the Actions tab of the screen's properties.

-- Remove all items from the list box.
DlgListBox.DeleteItem(CTRL_LIST_BOX, -1);

-- Add a new item called "Item One" to the list box.
DlgListBox.AddItem(CTRL_LIST_BOX, "Item One");
-- Set the associated data of "Item One" to _SourceFolder\\MyProgOne.exe.
DlgListBox.SetItemProperties(CTRL_LIST_BOX, 1, {ItemData=_SourceFolder.."\\MyProgOne.exe"});

-- Add a new item called "Item Two" to the list box.
DlgListBox.AddItem(CTRL_LIST_BOX, "Item Two");
-- Set the associated data of "Item Two" to "C\\MyProgTwo.exe".
DlgListBox.SetItemProperties(CTRL_LIST_BOX, 2, {ItemData="C\\MyProgTwo.exe"});

-- Add a new item called "Item Three" to the list box.
DlgListBox.AddItem(CTRL_LIST_BOX, "Item Three");
-- Set the associated data of "Item Three" to the string "This is the item three data".
DlgListBox.SetItemProperties(CTRL_LIST_BOX, 3, {ItemData="This is the item three data"});

This action script first removes all contents from the list box control. It then adds three new items and sets each of their associated data items.

 

You can paste the following code onto the On Next event, in between the else and the Screen.Next action. This event can be found on the Actions tab of the screen's properties.

-- Retrieve the table with all of the selected list box items.
tbSelected = DlgListBox.GetSelected(CTRL_LIST_BOX);

strSelectedLabels = "";
-- Loop through the table tbSelected and add the name, index and associated data of the selected item to a string.
for index, value in tbSelected do
    -- Get the properties of the selected list box item, so you can retrieve its name.
    tbProperties = DlgListBox.GetItemProperties(CTRL_LIST_BOX, value);
    -- Add the name of the listbox item (tbProperties.Text) and its index to the string for outputting.
    strSelectedLabels = strSelectedLabels.."Index: "..value.."\r\n".."Text: "..tbProperties.Text.."\r\n".."Associated Data: "..tbProperties.ItemData.."\r\n\r\n";
end

-- Display the labels and indexes of all selected listbox items in a dialog message.
Dialog.Message("ListBox", "The following list box items were selected:\r\n"..strSelectedLabels, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

This action script example is very similar to Example 1, however in this case, the item's associated data that was set on the On Preload event is also shown in the dialog message when you click the Next button.