【问题标题】:How to populate WIX combo box from Custom action如何从自定义操作填充 WIX 组合框
【发布时间】:2017-08-30 05:18:36
【问题描述】:

我在我的 UI 中添加了一个组合框。

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

此方法适用于列表框,但对于组合框会出错。

谁能看到我在这里做错了什么?

【问题讨论】:

    标签: wix windows-installer wix3.6


    【解决方案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>
    

    【讨论】:

    • 确保 ComboBox 表存在于 MSI 数据库中的正确方法是包含以下内容:
    【解决方案2】:

    我用过几乎相同的方法。

    你可以试试这个从文件中读取端口列表的例子:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多