2017-08-30 48 views
1

我已經添加了組合框到我的用戶界面。如何從自定義動作填充WIX組合框

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

我希望它從自定義操作中填充。我儘可能做到這一點。

這裏是我的功能來填充列表

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); 
      } 
     } 

然後我打電話:

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

此方法適用於列表框,但但對於組合框給出錯誤。

任何人都可以看到我在這裏做錯了嗎?

回答

1

基於this後,我可以填充組合框

中的.msi我不得不創建組合框的表將一個項目添加到一個值。

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

我在這裏添加的項目沒有在我的ComboBox上列出,所以現在這是可以的。如果有人知道如何以適當的方式做到這一點,歡迎回答。

我的控制器現在看起來像這樣。

<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

我已經使用了幾乎相同的方法。

你可以試着讀端口列表的這個例子從文件:

[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(); 
    }