vpodans
Posts: 35
Joined: Tue Dec 27, 2011 3:03 pm

Unable to populate multiple listboxes from script

I have a custom dialog with two listboxes. They have property names "LB1" and "LB2" respectively. Then, I have a powershell script in UI sequence:

Code: Select all

AI_SetMsiProperty AI_LISTBOX_DATA "LB1|val1|val2"
AI_SetMsiProperty AI_LISTBOX_DATA "LB2|val4|val5"
and I added a PopulateListBox helper action. Then, I added "PopulateListBox" action to custom dialog initialization. And here is the problem:

- if I use this script, only second listbox is populated. First gets blank.
- if I comment second line, then first listbox is populated

It seems that 'AI_SetMsiProperty AI_LISTBOX_DATA' overwrites any previously set values.

So, the question now is: how to populate multiple listboxes on same dialog using single powershell script?
®
Liviu
Posts: 1325
Joined: Tue Jul 13, 2021 11:29 am
Contact: Website

Re: Unable to populate multiple listboxes from script

Hello,

I'm afraid this is how our "PopulateListBox" custom action works. At the time it is launched it reads the value of the AI_LISTBOX_DATA property and populates the listbox whose property is specified in the value.

To implement your scenario you have to create different scripts - one for each of your ListBox. You also need to add the "Delete Items from List Box" custom action. Then you need to launch them in the following sequence on the Init Events of your dialog:
populate two listbox controls on the same dialog.png
populate two listbox controls on the same dialog.png (295.84 KiB) Viewed 81 times

Let us know if you have any questions.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
vpodans
Posts: 35
Joined: Tue Dec 27, 2011 3:03 pm

Re: Unable to populate multiple listboxes from script

Hi Liviu,

Thanks for your response! This is a very unfortunate behavior. The problem is that both listbox population logic share a lot in common, just slight differences and splitting them into separate scripts will cause a lot of duplicates and will be hard to maintain.

BTW, why do I need "Delete Items from List Box" custom action?
®
Liviu
Posts: 1325
Joined: Tue Jul 13, 2021 11:29 am
Contact: Website

Re: Unable to populate multiple listboxes from script

Hello,

If the DeleteFromListBox event is not used, then in some cases when the AI_LISTBOX_DATA property is set a second time, the new value may be appended to (concatenated with) the old value from the first list, instead of replacing it.

To avoid this and ensure the property is always updated correctly, we clear it before setting it again. The correct sequence is:

1. Set the AI_LISTBOX_DATA property with the first value.
2. Clear (remove) the value of the AI_LISTBOX_DATA property.
3. Set the AI_LISTBOX_DATA property again with the new list.

I also found a workaround that allows us to use a single script by using a custom property. Here’s how you can do it:

1. Create a new property in the Properties page.
2. In your script, when handling the second list, instead of setting the AI_LISTBOX_DATA property directly, set the custom property you just created. (For example, I named mine TEST.)

Code: Select all

$aiListboxData = "RUNNING_SERVICES_LIST" + "|" + $service
$LB2 = "LB2|val4|val5"

AI_SetMsiProperty AI_LISTBOX_DATA $aiListboxData
AI_SetMsiProperty TEST $LB2
3. On your dialog, instead of adding a second script, use a Set installer property action to assign the value of the TEST property to AI_LISTBOX_DATA:
init events.png
init events.png (69.98 KiB) Viewed 65 times

Let me know if that helped.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
vpodans
Posts: 35
Joined: Tue Dec 27, 2011 3:03 pm

Re: Unable to populate multiple listboxes from script

Now I understand how AI_LISTBOX_DATA works. I eventually split listboxes in different dialogs. My approach now is as follows:

1. Have UI sequence script which pre-calculate all listboxes at wizard launch and store them in temporary property
2. In dialog initialization actions, copy value from temp property to AI_LISTBOX_DATA and run PopulateListBox pre-defined action

it seems it does its work and I don't see any duplicates. But now I have only one listbox on a page, so should be safe.
®
Liviu
Posts: 1325
Joined: Tue Jul 13, 2021 11:29 am
Contact: Website

Re: Unable to populate multiple listboxes from script

Hello,

Thank you for your followup on this.

You can also use only one dialog if you follow the previous steps.

Let us know if you have any questions.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”