BobCrothers
Posts: 66
Joined: Wed Dec 05, 2007 10:58 pm

How to populate a listbox?

Hi,

I would like to display a dialog which allows the user to enter multiple IP addresses. I pictured an edit box where the user enters an IP address. The user would select an “Add” button. The add button would call a custom action which would add the IP to a listbox.

The examples I see use an SQL command to insert into a listbox, or use
Session.Property("COMBO")=strValue
to set the default value. How do I insert into the listbox without an SQL command, simply insert a string into the list of a listbox?

Thanks
Bob
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

Note that when populating a listbox, the new values will not be shown if the button which adds the values is on the same dialog as the listbox.

Here are the steps to do what you need:
- in the "Install Parameters" page create the property INDEX with the value 0
- create the "populate_listbox.vbs" file on the disk which contains this code:

Code: Select all

Set db = Session.Database
dim index
index=CInt(Session.Property("INDEX"))
Cmd = "INSERT INTO `ListBox` (`Property`,`Order`,`Value`,`Text`)"
Cmd = Cmd & " VALUES ('LISTBOX','" &  index & "','" & Session.Property("ADD_LIST") & "','"
Cmd = Cmd & Session.Property("ADD_LIST") & "') TEMPORARY"     
Set view = db.OpenView( Cmd )
view.Execute
view.Close
index=index+1
Session.Property("INDEX")=Cstr(index)
- add under "UI Custom Actions" the "populate_listbox.vbs" file as an Attached custom action in the "Custom Actions" page
- make sure that the "Function Name" field in the "Custom Action Properties" page is empty
- in the "Dialogs" page go to your custom dialog
- for the listbox set the "Property Name" field in the "Properties" section to LISTBOX
- for the editbox set the "Property Name" field in the "Properties" section to ADD_LIST
- select the button that will add the values and create this Published control event:

Code: Select all

DoAction               populate_listbox.vbs               AI_INSTALL
The user can now add the values one by one, but the values will be visible only if the listbox is on another dialog which comes after the one with the Add button.

You can read more about the Events Editor here:
http://www.advancedinstaller.com/user-g ... ditor.html

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
BobCrothers
Posts: 66
Joined: Wed Dec 05, 2007 10:58 pm

Thank you Cosmin, for the detailed answer, that is what I need. I’ll give this a try.

Bob
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Predefined CAs for working with ComboBox and ListBox control

Hi,

Starting with version 6.3, AI includes predefined Custom Actions for populating, deleting from and extracting data from ComboBox and ListBox controls.

You will find a tutorial and sample projects in the AI help file or online user guide.

For any questions or comments do not hesitate to contact us at support at advancedinstaller dot com.

Regards,
Ionut
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/

Return to “Common Problems”