watersco
Posts: 7
Joined: Mon Dec 11, 2006 6:45 am

Adding items to a combobox from a script

Hi,

I am trying to work out if AI can be used for my project.

I want to populate a combobox in a custom dialog from a vbs script. Can someone point me to any sample code which shows something like this?

Thanks,

Chris.
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,
I want to populate a combobox in a custom dialog from a vbs script. Can someone point me to any sample code which shows something like this?
Here is a script that populate a combobox:

Code: Select all

Set db = Session.Database

For index = 0 to 2
    SQLCmd = "INSERT INTO `ComboBox` (`Property`,`Order`,`Value`,`Text`)"
    SQLCmd = SQLCmd & " VALUES ('MY_PROP','" &  index & "','" & index & "','"
    SQLCmd = SQLCmd & "Test" & index & "') TEMPORARY"     
    Set view = db.OpenView( SQLCmd )
    view.Execute
    view.Close
Next
Add this script as custom action in the "Custom Actions" page under "UI Custom Actions" section. "Function Name" field must be empty. Switch to "Dialogs" page and add a published event on the "Next" button of the dialog that is in front of the dialog that contains the combobox. Use those options for the published event:
Name: DoAction
Argument: select the custom action created above.

Note that MY_PROP is the property of the combobox control.

Hope this helps. Note that you need to modify this script to fit your needs.

Best Regards,
Gigi
_______________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
watersco
Posts: 7
Joined: Mon Dec 11, 2006 6:45 am

Thanks. That does exactly what I need.
Phobos
Posts: 85
Joined: Fri Sep 08, 2006 11:52 am
Location: Germany

Hi Gigi,

I need to populate a combobox too. The script you provided works fine, unfortunately I am not sure how to modify it to include the values I need. Here is a script that gets the values from the registry, and I want those values to appear in a combobox:

Code: Select all

On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Microsoft SQL Server"
strValueName = "InstalledInstances"
oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, _
    strValueName,arrValues
 
For Each strValue In arrValues
MsgBox strValue
Next
Is it possible to combine both scripts somehow? Thanks for the assistance.
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

In my script from previous post a SQL command is executed that insert (temporary) some rows in the ComboBox table. The columns for this table are:

Property: the property of the combobox.
Order: the order that the items are displayed in the combobox.
Value: the value of an item.
Test: the text that will be displayed in the combobox.

Here is the script that reads some values from registry and populate the combo:

Code: Select all

Set db = Session.Database

On Error Resume Next

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\Microsoft\Microsoft SQL Server"
strValueName = "InstalledInstances"
oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, _
    strValueName,arrValues

index = 1

For Each strValue In arrValues
    SQLCmd = "INSERT INTO `ComboBox` (`Property`,`Order`,`Value`,`Text`)"
    SQLCmd = SQLCmd & " VALUES ('MY_PROP','" &  index & "','" & strValue & "','"
    SQLCmd = SQLCmd & strValue & "') TEMPORARY"     
    Set view = db.OpenView( SQLCmd )
    view.Execute
    view.Close
    index = index + 1
Next 
Best Regards,
Gigi
______________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
Phobos
Posts: 85
Joined: Fri Sep 08, 2006 11:52 am
Location: Germany

Thanks alot Gigi, thats exactly what I was looking for.
splay
Posts: 58
Joined: Tue May 15, 2007 6:09 pm

Folders

Hey guys,

I am doing the same kind of thing but dont have the luxury of one key that holds all the installed instances names.

I do have a folder that will contain child folders and each of those folder names will be the name of the installed instance.

Example:

SOFTWARE\eWare\Config\instance_1
SOFTWARE\eWare\Config\instance_2
SOFTWARE\eWare\Config\instance_3

Any ideas, truly appreciated.

Tony
Ionut
Posts: 605
Joined: Tue Nov 22, 2005 11:29 am
Contact: Website

Predefined CAs for working with ComboBox and ListBox control

Hi,

Starting with version 6.3, AI includes predefined Custom Actions for populating, deleting from and extracting data from ComboBox and ListBox controls.

You will find a tutorial and sample projects in the AI help file or online user guide.

For any questions or comments do not hesitate to contact us at support at advancedinstaller dot com.

Regards,
Ionut
Denis Toma
Advanced Installer Team
http://www.advancedinstaller.com/

Return to “Common Problems”