How do I dynamically populate a combo box dialog control?
With Wise for Windows Installer, Wise for Visual Studio .NET, and the Windows Installer Editor tool in Wise Package Studio, you can create and modify dialogs for your installation. In the dialogs you can add combo boxes, then set them up to dynamically populate in the database. This allows you to offer the end user more options based on information gathered from the target computer.
In most cases, you know the combo box options; because they are static, you can add the options during the installation development. To do this, add the combo box and its options to the dialog using the Dialog tab in Setup Editor. Other times, however, the combo box options are not static: you have not decided on them during installation development, or they changed after the installation was developed. The solution in these instances is to dynamically create and populate the combo box control during the installation.
Because the dialog control information is held within the MSI database, this list must be added as new rows to the MSI database during runtime. This requires you to use a custom action to create the rows in the .MSI that will dynamically populate the combo box. This article explains how to create this type of control.
Note: This article requires basic knowledge of VB Script. The data for the combo box in the example uses constants included in the VB Script. More advanced knowledge of VB Script may be necessary to use data from alternative locations.
There are three sets of procedures to dynamically create a list for a combobox at runtime.
To create a combo box control:
- Start Wise for Windows Installer, Wise for Visual Studio .NET, or Wise Package Studio. If you are using Wise Package Studio, open Windows Installer Editor from the Tools pane.
- Click the Setup Editor tab, then click the Dialogs tab.
- Select the dialog from the dialog list to which you want to add the control. When the dialog appears on the right, right-click on it. In the menu, select Add > Combo box. The Properties for Combo box dialog appears.
- Click the New button next to the Property field. The Property Details dialog appears.
- In the Name field, enter a property name. For this example, you can enter COMBO. Click OK.
- Click OK to close the Properties for Combo box dialog.
To create a VB Script custom action to dynamically populate the combo box:
- Click the MSI Script tab.
- Select Normal Installation from the Installation Mode drop-down list.
- Click the User Interface tab below the Installation Sequence pane.
- Scroll down in the Installation Sequence until you find the MigrateFeatureStates action.
- Click the script line below MigrateFeatureStates action, then double-click on the Call VBScript From Installation in the Custom tab of the Actions pane. The Call VB Script From Installation dialog appears.
- Fill in the fields on the Details tab in the dialog as follows:
- Custom Action Name. Enter any string. For this example, you can enter Combo box.
- Script File. Browse and open the Combobox.vbs file provided with this article.
- Script Function Call. Enter Combo for the function call.
- Click OK.
Modifying the VB Script (.VBS file) provided with this article:
The Combobox.vbs script accompanying this article has two functions defined: Combo() and addToComboBox(). For samples of how to implement the Combobox.vbs file, see the PopulateCombobox.wsi and PopulateCombobox.msi files included with this article.
- Modify the Combo() function by setting the four properties below.
- ComboProp. Enter the name of the Windows Installer property associated with your Combobox control. We used COMBO in the steps above.
- ComboOrder. Enter an integer that can be used to sort the combo box items if the Sort check box is marked on the Properties for Combo box dialog. If this check box is not marked, Windows Installer sorts the items automatically using the ComboText values.
- ComboValue. Enter the value of the property to set if the user selects this item. In this example, the value is COMBO.
- ComboText. Enter text to display to the user.
Instead of the Modify procedures above, you might want to use a VB Script to gather information from the destination machine using registry key values, an .INI file, text file, or using another method. If you use one of these methods, use the obtained values to populate the ComboProp, ComboOrder, ComboValue, and ComboText properties. Then call the addToComboBox() function.
The addToComboBox() function adds the appropriate row to the Combobox table of the .MSI file using the View object from the Windows Installer object model. To learn more about the Windows Installer properties and methods available within VB Script including those in this function, see the MicrosoftÂ® WindowsÂ® Installer SDK Help. The following Windows Installer SDK pages are relevant to this article:
- Control Table
- ComboBox Table
- Custom Action Type 6 (This is the "Call VB Script From Installation")
- Database Object
- OpenView Method
- View Object
- Execute Method
With knowledge of VB Script and Windows Installer dialog control tables, dynamically populating a control box can give you greater flexibility in your installations. For instance, use the procedures in this article to dynamically populate other controls in your installations. This can make your installations more versatile and robust.
Rate this Article