Microsoft KB Archive/291329

{|
 * width="100%"|

HOWTO: Dynamically Populate a ListBox Control in Windows Installer

 * }

Q291329

-

The information in this article applies to:


 * Microsoft Windows Installer, versions 1.0, 1.1, 1.2

-

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 &quot;ListBox Table&quot; in the Platform SDK:

"http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/msi/tref_5f1h.htm" 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 &quot;Sample.msi&quot; 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) = &quot;Item 1&quot; a(2) = &quot;Item 2&quot; a(3) = &quot;Item 3&quot;

Set oInstaller = CreateObject(&quot;WindowsInstaller.Installer&quot;) 'create Installer object Set oDatabase = oInstaller.OpenDatabase(&quot;c:\sample.msi&quot;, 1) 'open database to be changed Set vw = oDatabase.OpenView(&quot;SELECT * FROM `ListBox`&quot;) Set rc = oInstaller.CreateRecord(4) For I = 1 To 3 rc.StringData(1) = &quot;SampleProp&quot; 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

'Release the Objects

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

Shell &quot;msiexec /i c:\sample.msi&quot;

Set oInstaller = Nothing

Unload Me

End Sub