2017-08-30 7 views
1

Ich habe ein Kombinationsfeld zu meiner Benutzeroberfläche hinzugefügt.So füllen Sie das WIX-Kombinationsfeld aus Benutzerdefinierte Aktion

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

Ich möchte es von einer benutzerdefinierten Aktion bevölkern. Ich habe es so gemacht, wie ich gebrüllt habe.

Hier ist meine Funktion Listen zu füllen

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

Und dann rufe ich als:

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

Diese Methode für Listenfelder funktioniert, aber aber für Combo-Box Fehler gibt.

Kann jemand sehen, was ich hier falsch mache?

Antwort

1

Basierend auf this Post, ich das Kombinationsfeld füllen könnte

zu Combobox Tabelle in der .msi erstellt werden musste ich Füge ein Element zu einem Wert hinzu.

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

Das hier hinzugefügte Element wurde nicht auf meiner ComboBox aufgelistet, also ist das für jetzt OK. Wenn jemand weiß, wie man das richtig macht, sind Antworten willkommen.

Mein Controller sieht jetzt so aus.

<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

Ich habe fast die gleiche Methode verwendet.

können Sie versuchen, dieses Beispiel für das Lesen Ports Liste von Datei:

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