PDA

View Full Version : Programmatically Adding Items to a ComboBox



Scott Duckworth
04-11-2002, 09:16 AM
I would like to programmatically add items do a ComboBox directly in the .ISM file. I'm currently using the COM interface and Visual Basic to modify such items as the product version and other misc. properties before I issue a build. These items will be read from a file and will be different for each client build. I need to have the items in the ISM file because we do not want to deploy the configuration file to the client.


Thanks

RobertDickau
04-11-2002, 01:33 PM
It doesn't read the data from a text file, but this should give the general idea:


Set oMSI = CreateObject("WindowsInstaller.Installer")

Set oDB = oMSI.OpenDatabase("ComboTest.ism", 2) ' i.e., open direct read-write


Set oView = oDB.OpenView("INSERT INTO `ComboBox` " & _
"(`ComboBox`.`Property`, `ComboBox`.`Order`, `ComboBox`.`Value`, `ComboBox`.`Text`) " & _
"VALUES ('COMBOPROP', 1, 1, 'First Choice')")

oView.Execute
oView.Close

Set oView = oDB.OpenView("INSERT INTO `ComboBox` " & _
"(`ComboBox`.`Property`, `ComboBox`.`Order`, `ComboBox`.`Value`, `ComboBox`.`Text`) " & _
"VALUES ('COMBOPROP', 2, 2, 'Second Choice')")

oView.Execute
oView.Close

Set oView = oDB.OpenView("INSERT INTO `ComboBox` " & _
"(`ComboBox`.`Property`, `ComboBox`.`Order`, `ComboBox`.`Value`, `ComboBox`.`Text`) " & _
"VALUES ('COMBOPROP', 3, 3, 'Third Choice')")

oView.Execute
oView.Close

' etc.

oDB.Commit: Set oMSI = Nothing

Scott Duckworth
04-12-2002, 06:03 AM
Thank you very much!

But, I have one last question, what do I reference in a Visual Basic project. Is the WindowsInstaller, Database, and View objects only available in Script?

RobertDickau
04-12-2002, 08:03 AM
In VB, you'll have to pull down the Project menu, select References, and add "Microsoft Windows Installer Object Library"; after that, you can use the Object Browser, etc., to use the MSI Automation interface.

Scott Duckworth
04-12-2002, 08:07 AM
Again, Thank you very much for the help.