Question

I am trying to populate values using custom actions and want to bind the values into combobox which is inside product.wxs.

Can anyone guide me how to bind values if I want to populate a list of countries inside the combobox?

I am struggling with how to pass this value so the values will show inside combox while executing my MSI setup.

Below provide the code which I am trying:

    public static ActionResult FillList(Session xiSession)
    {

        Dictionary<string, string> _co = new Dictionary<string, string>();
        _co.Add(String.Empty, String.Empty);
        _co.Add("US", "United States");
        _co.Add("CA", "Canada");
        _co.Add("MX", "Mexico");

        xiSession.Log("Return success");
        return ActionResult.Success;
    }

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate />

    <Feature Id="ProductFeature" Title="SetupProjectComboTest" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
    </Feature>

<UI>
  <UIRef Id="WixUI_Mondo" />

  <Dialog Id="MyCustomDlg"  Width="500" Height="260">
    <Control Id="ComboBoxMain" Type="ComboBox" X="10" Y="60" Width="300" Height="17" Property="COUNTRIES" />
    <Control Id="ButtonMain" Type="PushButton" X="320" Y="60" Width="40" Height="17" Text="Show">
      <Publish Property="COMBOVALUEFORMATTED" Order="1"  Value="[COUNTRIES]" />
    </Control>
    <Control Id="LabelMain" Type="Text" X="10" Y="80" Width="360" Height="17" Property="COMBOVALUEFORMATTED" Text="[COMBOVALUEFORMATTED]" />

  </Dialog>
</UI>

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="SetupProjectComboTest" />
        </Directory>
    </Directory>
</Fragment>

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
        <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
        <!-- <Component Id="ProductComponent"> -->
            <!-- TODO: Insert files, registry keys, and other resources here. -->
        <!-- </Component> -->
    </ComponentGroup>
</Fragment>

Was it helpful?

Solution

You need to insert row into ComboBox table to bind the List values. If you open the msi in ORCA Editor, you can find the msi tables and rows.

You should include EnsureTable element if you don’t use any other ComboBox element in your msi.

  <EnsureTable Id="ComboBox"/>

You can insert the rows from Custom action.

  static int index = 1;
 public static void FillComboBox(Session session, string text, string value)
    {
        View view = session.Database.OpenView("SELECT * FROM ComboBox");
        view.Execute();

        Record record = session.Database.CreateRecord(4);
        record.SetString(1, "COUNTRIES");
        record.SetInteger(2, index);
        record.SetString(3, value);
        record.SetString(4, text);

        view.Modify(ViewModifyMode.InsertTemporary, record);
        view.Close();
        index++;
    }

Inside the Custom action call the FillComboBox method.

   public static ActionResult FillList(Session xiSession)
    {

        FillComboBox(xiSession, "US", "United States");
        FillComboBox(xiSession, "CA", "Canada");
        FillComboBox(xiSession, "MX", "Mexico");          

        return ActionResult.Success;
    }

Execute the Custom action in InstallUIsequence before run that Combo Box dialog.

   <InstallUISequence>
     <Custom Action="INSERT_ROWS" After="AppSearch">Not Installed</Custom>
  </InstallUISequence>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top