How to populate WIX combo box from Custom action

2k views Asked by At

I have added a combo box to my UI.

<Control Id ="ExistingPortCombo" Type="ComboBox" X="120" Y="120" Width="200" Height="50" Property="ComboSelectedPort" ComboList="yes" >
<ComboBox Property="ComboSelectedPort" />
</Control>

I want it to populate from a custom action. I trid to do so as bellow.

Here is my function to populate lists

static int index = 0; 
  private static void AddRecordToList(string propertyName,string text,string value,string control)
        {
            try
            {
                View view = CurrentSession.Database.OpenView("SELECT * FROM " + control);

                view.Execute();

                Record record = CurrentSession.Database.CreateRecord(4);

                record.SetString(1, propertyName);
                record.SetInteger(2, ++index);
                record.SetString(3, text);
                record.SetString(4, value);

                view.Modify(ViewModifyMode.InsertTemporary, record);
                view.Close();
            }
            catch (Exception ex)
            {
                global::System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }

And then I call as:

AddRecordToComboBox("ComboSelectedPort", text, value,"ComboBox");

This method works for list boxes but but for Combo box gives errors.

Can anyone see what i am doing wrong here?

2

There are 2 answers

1
mhs On BEST ANSWER

Based on this post, I could populate the combo box

to be created combobox table in the .msi I had to add a item to a value.

<ListItem Value="1" Text="DumyData" />

the item i added here was not listed on my ComboBox, so for now this is OK for now. If any one knows how to do this by a proper way answers are welcome.

My controller is now looks like this.

<Control Id ="ExistingPortCombo" Type="ComboBox" X="120" Y="120" Width="200" Height="50" Property="ComboSelectedPort" ComboList="yes" >
<ComboBox Property="ComboSelectedPort" >
  <ListItem Value="1" Text="DumyData" />
</ComboBox>

0
Arkady Sitnitsky On

I have used almost the same method.

You can try this example of reading ports list from file:

    [CustomAction]
    public static ActionResult GetPortsFromFile(Session session)
    {
            const string tableName = "ComboBox";
            const string Property = "ComboSelectedPort";
            const string PortsConfigFile = "Ports.txt";

            string strPorts = File.ReadAllText(PortsConfigFile);

            string[] PortsList = strPorts.Split(',');

            int order = 2;
            foreach (var Port in PortsList)
            {
                string value = Port.ToString();
                string text = Port.ToString();
                object[] fields = new object[] { Property, order, value, text };
                InsertRecord(session, tableName, fields);

                order++;
            }

            return ActionResult.Success;
    }

    private static void InsertRecord(Session session, string tableName, Object[] objects)
    {
        Database db = session.Database;
        string sqlInsertSring = db.Tables[tableName].SqlInsertString + " TEMPORARY";
        session.Log("SqlInsertString is {0}", sqlInsertSring);
        View view = db.OpenView(sqlInsertSring);
        view.Execute(new Record(objects));
        view.Close();
    }