如何从自定义操作填充WIX组合框

时间:2017-08-30 05:18:37

标签: wix windows-installer wix3.6

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

$ulat = $data['ULat'];
$ulong = $data['ULong'];

$sql = "SELECT PostId, (3959 * acos(cos(radians($ulat)) * cos(radians(LocationLat))
    * cos(radians(LocationLong) - radians($ulong)) + sin(radians($ulat))
    * sin(radians(lLocationLatat)))) AS distance
    FROM VehicleDetails HAVING distance < 250 ORDER BY distance LIMIT 0, 20";

if( $query = !mysqli_query($con, $sql ) )
{
    echo "Error occurred! :" . mysqli_error( $con );
}
var_dump($query);

我希望它从自定义操作中填充。我乖乖地这样做。

这是我填充列表的功能

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

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

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

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分: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();
    }