Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call custom action in WIX on change of value in Combox

Am stuck with combo box and custom action in WIX installer.

I have a combo box(drop down) containing few values. I want to show some text on the screen (unique for each item in dropdown) when the user selects a value from this drop down.

In .Net we can do this easily as we have different events pre-defined. But in WIX I don't see any such event.

Has someone faced the same problem? Or can guide me on how can I get it done.

like image 529
Sunil Agarwal Avatar asked Aug 04 '11 10:08

Sunil Agarwal


2 Answers

Windows Installer (the underlying technology) doesn't let you do so. Literally, it doesn't publish any event when the combobox (dropdown) value changes. You'll have to add a button, for instance, for user to click when he/she changed the value in the combobox...

Alternatively, you can switch to the EmbeddedUI technique (WiX element and MSI table), but it is much more advanced...

UPDATE: a sample of using button click to update the text.

<UI>
  ...
  <ComboBox Property="WIX_VERSIONS">
    <ListItem Value="Windows Installer XML 3.0" />
    <ListItem Value="Windows Installer XML 3.5" />
    <ListItem Value="Windows Installer XML 3.6" />
  </ComboBox>
  ...
  <Dialog Id="MyCustomDlg">
    ...
      <Control Id="ComboBoxMain" Type="ComboBox" X="10" Y="60" Width="300" Height="17" Property="WIX_VERSIONS" />
      <Control Id="ButtonMain" Type="PushButton" X="320" Y="60" Width="40" Height="17" Text="Show">
        <Publish Property="COMBOVALUEFORMATTED" Value="You've chosen the [WIX_VERSIONS] version of the toolset" />
      </Control>
      <Control Id="LabelMain" Type="Text" X="10" Y="80" Width="360" Height="17" Property="COMBOVALUEFORMATTED" Text="[COMBOVALUEFORMATTED]" />
    ...
  </Dialog>
</UI>

PushButton can publish more events, for instance, DoAction, which is used to run a custom action on button click. This might be more relevant in your case.

like image 107
Yan Sklyarenko Avatar answered Nov 09 '22 13:11

Yan Sklyarenko


There is a way to do this in WiX. You just need to manufacture your own changed event.

We compare our DoAction condition to another property which will hold the previous state of the Combobox - VIRTUALWEBSITEOLD

Execute a custom action in the ComboBox when old does not equal new:

    <Control Id="WebSite" Type="ComboBox" Width="180" Height="18" X="120" Y="48" ComboList="no" Property="VIRTUALWEBSITE">
       <Publish Event="DoAction" Value="LansaInitVirtualFolders"><![CDATA[VIRTUALWEBSITE <> VIRTUALWEBSITEOLD]]></Publish>
    </Control>

Then the Custom Action performs the same comparison as the DoAction (probably not required) and then saves the Combobox value in the OLD property.

  Tstring wszWebsite = ReadProperty( _T( "VIRTUALWEBSITE") );
  Tstring wszWebsiteOld = ReadProperty( _T ( "VIRTUALWEBSITEOLD" ) );

  // If unchanged ignore request
  if ( wszWebsite == wszWebsiteOld ) return true ;

 [Do Some stuff]

  // Set the saved state of the combobox so we don't get called again until it changes
  if ( nResult == ERROR_SUCCESS || nResult == ERROR_NO_MORE_ITEMS)
  {
     WriteProperty( _T("VIRTUALWEBSITEOLD" ), wszWebsite.c_str () );
  }

(Note: Also need to use Twin Dialog Pattern if updating, say, a listbox control. If your control doesn't update but Next and Back DOES update it, then Twin Dialog Pattern will ensure it updates)

like image 39
RobG Avatar answered Nov 09 '22 12:11

RobG