Working with Windows Installer ComboBox and ListBox controlsThis tutorial will describe how Windows Installer ComboBox and ListBox controls can be used for various user interface scenarios. Both controls allow the user to select a single value from a list of predetermined values. A typical installation task would be to populate these controls dynamically with data retrieved at install time (for instance, a list of local SQL Server databases may be required). Another usage scenario would be to allow the user to define a list of IP addresses (or address ranges) which can be used to configure the Windows Firewall or saved to the registry and used subsequently by your application. These operations involve inserting records manually into the ComboBox and ListBox tables, which is cumbersome, at the very least. For this reason, Advanced Installer (starting with version 6.3) includes predefined custom actions to populate, delete from and extract data from ComboBox and ListBox controls. In order to use these custom actions, an Enterprise version of Advanced Installer is required. The following sections describe how Windows Installer stores ComboBox and ListBox data inside the MSI database, how the predefined custom actions can be used, as well as typical UI scenarios involving these controls.
Introductory conceptsSimilar to other Windows Installer controls, ComboBoxes and ListBoxes have an attached property which can be set in the right Properties pane. As described below, all the items from a ComboBox or ListBox control are tied to the same property. These controls have several attributes which can also be set in the right Properties pane. An important attribute is "Sort By Index" which specifies whether the items should be sorted alphabetically (the attribute is False) or sorted according to the order defined in the ComboBox or ListBox tables (if the attribute is True). In Advanced Installer, in order to add items to a ComboBox or ListBox control, select the "Control Data" context menu item or press the Ctrl + D keys while the focus is on the control. The data for these controls is stored in the ComboBox and ListBox tables inside the MSI database and each record from these tables represents a control item. Both tables have the following 4 columns:
Predefined custom actions for working with ComboBox and ListBox controlsThere are 3 predefined custom actions for working with ComboBox controls, namely:
Their ListBox equivalents are named PopulateListBox, DeleteFromListBox and ExtractListBoxData, respectively. The custom actions that work with ComboBox controls use as input/output property AI_COMBOBOX_DATA, while their ListBox counterparts use the AI_LISTBOX_DATA property. More specifically, in order to populate a ComboBox control, you will set the AI_COMBOBOX_DATA property to a list of values that should be inserted, respecting a special format (which will be described in more detail in the following section). Then you will invoke the predefined PopulateComboBox custom action which will do the actual insertion. On return, the custom action will set the AI_COMBOBOX_DATA property to a status message indicating the success or failure of the operation. In conclusion, the following steps are required in order to use these predefined custom actions in your project:
The following sections describe the format that should be used to set the AI_COMBOBOX_DATA and AI_LISTBOX_DATA properties in each case (populating, deleting from and extracting data from ComboBox and ListBox controls). Additionally, the return status messages for each predefined custom action will be described. Populating ComboBox and ListBox controlsYou will use the PopulateComboBox or PopulateListBox predefined custom actions, depending on the type of control you wish to insert data into. The input format for the AI_COMBOBOX_DATA (AI_LISTBOX_DATA) property is: Property#OrderStart#OrderDelta|Value1#Text1|Value2#Text2|Value3#Text3|... where Property is the property attached to the ComboBox (ListBox) control in which data should be inserted and OrderStart, OrderDelta are used to compute the value of the Order column for each item (refer to the first section above for details). OrderStart and OrderDelta are optional (if missing, they will both default to 10), as well as the Text for each item. There is no limit to the number of items that can be inserted. The first item ("Value1") will have the Order column set to OrderStart (or 10 if no OrderStart was specified), the second item ("Value2") will have the order OrderStart + OrderDelta, the third item ("Value3") will have the order OrderStart + 2 * OrderDelta and so on, the n-th item will have the order OrderStart + (n-1) * OrderDelta.
Some examples for specifying the AI_COMBOBOX_DATA and AI_LISTBOX_DATA properties in this case:
On return, the predefined custom actions PopulateComboBox and PopulateListBox will set the AI_COMBOBOX_DATA (or AI_LISTBOX_DATA) property to one of the following status messages, in order to indicate the success or failure of the insertion:
Deleting items from ComboBox and ListBox controlsYou will use the DeleteFromComboBox or DeleteFromListBox predefined custom actions, depending on the type of control you wish to delete data from. The input format for the AI_COMBOBOX_DATA (AI_LISTBOX_DATA) property is: Property|Value1|Value2|Value3|... where Property is the property attached to the ComboBox (ListBox) control from which data will be deleted. There is no limit to the number of items that can be deleted. If no values to be deleted are specified, then all the items from the ComboBox or ListBox control are deleted. Some examples for specifying the AI_COMBOBOX_DATA and AI_LISTBOX_DATA properties in this case:
On return, the predefined custom actions DeleteFromComboBox and DeleteFromListBox will set the AI_COMBOBOX_DATA (or AI_LISTBOX_DATA) property to one of the following status messages, in order to indicate the success or failure of the delete operation:
Therefore, if you are going to allow the user to delete ComboBox or ListBox records at install time, there are 2 possibilities to avoid the issue discussed above:
Extracting item values and text from ComboBox and ListBox controlsYou will use the ExtractComboBoxData or ExtractListBoxData predefined custom actions, depending on the type of control you wish to extract data from. The input format for the AI_COMBOBOX_DATA (AI_LISTBOX_DATA) property is: Property where Property is the property attached to the ComboBox (ListBox) control from which data will be extracted. On return, the AI_COMBOBOX_DATA (AI_LISTBOX_DATA) property will contain the extracted data, in the following format: Value1#Text1|Value2|Value3#Text3|... If an item has no text, only the value will be extracted, in which case the "#" character will be omitted. If the respective control contains no items, AI_COMBOBOX_DATA (AI_LISTBOX_DATA) will be empty (not set). If an error occurs, the corresponding property will be set to ERROR.
Refreshing ComboBox and ListBox controls: the "twin dialog" methodWindows Installer does not automatically refresh ComboBox and ListBox controls once the underlying MSI tables with the same name are modified. Only after switching to a different dialog are these tables re-read. Hence, if you are going to allow the user to dynamically add and remove items to/from ComboBox or ListBox controls, you will need to use the so-called (among Windows Installer setup authors) "twin dialog" method in order to refresh the controls. Otherwise, the user will have to change to the next or previous dialog in the sequence and then return to the current dialog in order to see his change to the ListBox/ComboBox control. Basically, the "twin dialog" method involves the following:
Example projectsDownload and unzip the ComboBox and ListBox sample projects to better understand the concepts discussed above. An Enterprise version of Advanced Installer (version 6.3 or greater) is required in order to build and run the projects. There are 2 example projects within the archive named "DualListExample.aip" and "ComboListExample.aip", presenting 2 common ListBox usage scenarios, as well as 1 ComboBox usage scenario. The "scripts" folder within the archive contains the supporting VBScript custom actions for each project. Usage scenario 1: moving items dynamically between two side-by-side ListBox controlsSince Windows Installer ListBox controls do not support the selection of multiple items, using 2 side-by-side ListBox controls and allowing the user to move items between them might represent a good alternative solution. The sample project "DualListExample.aip" illustrates how this can be implemented. At install time the dialog could look like it is shown below:
A brief explanation regarding how the sample project is configured follows: 1. In the Install Parameters page there are defined 2 Properties (LIST_ORDER and LIST_ORDER_DELTA) that are used to compute the order of the items in both lists. Every time an item is added to the right list (and also removed from the left list) and vice-versa, the value of LIST_ORDER_DELTA is added to the value of LIST_ORDER. An improvement would be to maintain 2 distinct properties to hold the current order for each list, but this is not actually required since there will be a relatively small number of operations the user will perform (the Order column of the ListBox table can have a maximum value of 32767). 2. The Custom Actions page contains the predefined PopulateListBox, DeleteFromListBox and ExtractListBoxData custom actions, as well as VBScript custom actions that are executed when the "Add", "Remove" and "Extract" buttons (from DualListDlgA and DualListDlgB dialogs) are clicked. The code for these custom actions can be found in the file "DualListExample.vbs" inside the archive. 3. In the Dialogs page, 3 new custom dialogs have been created: DualListDlgA and DualListDlgB are twin dialogs and ListBoxDataSpawnDialog is a spawned dialog that is shown when the "Extract" button is clicked. 4. The "Add" button removes the selected item from the left list and adds it to the right list, while the "Remove" button does the opposite. Notice how the Published Events and Control Conditions have been configured for these 2 button controls. 5. The "Extract" buttons demonstrate the usage of the ExtractListBoxData predefined custom action - a spawned dialog is shown, containing the values from the corresponding ListBox control. 6. The left ListBox control is populated dynamically at install time via an Init Event in order to avoid the issue discussed in section 4 above. Usage scenario 2: Populating a ComboBox control with the output of an external programThe example we shall consider involves populating a ComboBox control with the system environment variables. At install time, the dialog can look like the following:
The environment variables and their values are obtained by running the internal set command of the command interpreter and redirecting the output to a text file. Subsequently, the file is read line by line and the ComboBox is populated. After this, the temporary text file is deleted. See how the Init Events have been configured for the ComboBoxDemoDlg dialog from "ComboListExample.aip". The corresponding VBScript custom actions can be found inside "ComboListExample.vbs" inside the zip archive. Usage scenario 3: Dynamically adding/removing items to/from a ListBox controlIf your application requires a list of values that should be specified by the user at install time, a dynamically populated ListBox control would be an appropriate solution. For example, if a list of IP addresses (or address ranges) is required, the dialog could look like this:
This scenario uses the "twin dialog" method in order to dynamically refresh the contents of the ListBox control. See how the dialogs ListBoxDemoDlgA and ListBoxDemoDlgB (from ComboListExample.aip) have been configured. | |
|
| Privacy Policy | Windows Installer | Search Engine Ranking | Link Analyzer | ||
| © 2002 - 2008 Caphyon Ltd. Trademarks belong to their respective owners. All rights reserved. | ||