How To Dynamically Populate a ListBox Control in Windows Installer (291329)



The information in this article applies to:

  • Microsoft Windows Installer 1.0
  • Microsoft Windows Installer 1.1
  • Microsoft Windows Installer 1.2

This article was previously published under Q291329

SUMMARY

This article describes how to dynamically populate a ListBox control by using code in a Windows Installer package.

MORE INFORMATION

In order to populate a ListBox control, you must first populate the ListBox table. For more information on populating the ListBox table, see the Help topic "ListBox Table" in the Platform SDK: You can populate the ListBox table by using the CreateRecord method (which is also documented in the Microsoft Platform SDK at http://msdn.microsoft.com/library/psdk/msi/vref_5ack.htm). After the ListBox table has been populated, you can then call the .msi package by using the shell command.

Create a new blank standard .exe project in Microsoft Visual Basic. Paste the following code in the general declarations of the project. You must also have an .msi package called "Sample.msi" located on the root of C:\ drive. In order to see this example work, you must also create a dialog box that has a ListBox control on it. The ListBox control must have its property set to SampleProp. This is the property that links it to the ListBox table.
Dim oInstaller As WindowsInstaller.Installer
Dim oDatabase As WindowsInstaller.Database
Dim vw As WindowsInstaller.View
Dim rc As WindowsInstaller.Record


Private Sub Form_Load()
Dim a(3)

a(1) = "Item 1"
a(2) = "Item 2"
a(3) = "Item 3"

    Set oInstaller = CreateObject("WindowsInstaller.Installer") 'create Installer object
    Set oDatabase = oInstaller.OpenDatabase("c:\sample.msi", 1) 'open database to be changed
    
    Set vw = oDatabase.OpenView("SELECT * FROM `ListBox`")
    
    Set rc = oInstaller.CreateRecord(4)
    
    For I = 1 To 3
    
    rc.StringData(1) = "SampleProp"
    rc.StringData(2) = I
    rc.StringData(3) = I
    rc.StringData(4) = a(I)
          
    vw.Execute rc
    vw.Fetch
    vw.Modify msiViewModifyInsert, rc
        
    oDatabase.Commit
                        
    Next I<BR/>

    'Release the Objects<BR/>

    Set vw = Nothing
    Set oDatabase = Nothing
    Set oSummary = Nothing
    Set oInstaller = Nothing
    Set rc = Nothing
    
' ** Run the package

Shell "msiexec /i c:\sample.msi"

Set oInstaller = Nothing

Unload Me<BR/>

End Sub
				

Modification Type:MinorLast Reviewed:10/6/2004
Keywords:kbhowto KB291329