gpt4 book ai didi

Wix 将项目加载到 ComboBox

转载 作者:行者123 更新时间:2023-12-04 19:11:39 25 4
gpt4 key购买 nike

我需要使用自定义操作将项目加载到组合框中。

用户界面.wxs:

            <Control Id="Server" Type="ComboBox" X="30" Y="65" Width="200" Height="18" Property="DATABASE_SERVER">
<ComboBox Property="DATABASE_SERVER">
<ListItem Text="[DATABASE_SERVER]" Value="[DATABASE_SERVER]" />
</ComboBox>
<Publish Property="LOGON_VALID" Value="0">1</Publish>
</Control>

自定义操作
private static ActionResult EnumSqlServersIntoComboBox(Session session, IEnumerable<DataRow> rows)
{
try
{
Debugger.Break();

session.Log("EnumSQLServers: Begin");

// Grab the combo box but make sure I'm getting only the one
// from WebAppInstallDlg.
View view = session.Database.OpenView("SELECT * FROM ComboBox WHERE ComboBox.Property='DATABASE_SERVER'");
view.Execute();

Int32 index = 1;
session.Log("EnumSQLServers: Enumerating SQL servers");
foreach (DataRow row in rows)
{
String serverName = row["Name"].ToString();

// Create a record for this web site. All I care about is
// the name so use it for fields three and four.
session.Log("EnumSQLServers: Processing SQL server: {0}", serverName);

Record record = session.Database.CreateRecord(4);
record.SetString(1, "DATABASE_SERVER");
record.SetInteger(2, index);
record.SetString(3, serverName);
record.SetString(4, serverName);

session.Log("EnumSQLServers: Adding record");
view.Modify(ViewModifyMode.InsertTemporary, record);
index++;
}

view.Close();

session.Log("EnumSQLServers: End");
}
catch (Exception ex)
{
session.Log("EnumSQLServers: exception: {0}", ex.Message);
throw;
}

return ActionResult.Success;
}

我想要实现的是在所有加载的 sql 服务器旁边有一个带有下拉箭头的输入文本框。
enter image description here

sql server 加载到组合框的唯一时间是我将 UI 代码更改为:
<Control Type="ComboBox" Property="DATABASE_SERVER" Id="Server" Width="180" Height="16" X="110" Y="60" ComboList="yes" Sorted="yes" />

通知 ComboList="yes"元素。但这对我不起作用,因为这使组合框成为下拉项目,我希望能够在备用选项中“键入”。

最佳答案

我想到了:

Dialogs.wxs:

...                <Control Id="ServerLabel" Type="Text" X="20" Y="62" Width="80" Height="25" NoPrefix="yes" Text="SQL Database:" />
<Control Id="Server" Type="ComboBox" Height="16" Width="180" X="110" Y="60" Property="DATABASE_SERVER">
<ComboBox Property="DATABASE_SERVER">
<ListItem Text="[DATABASE_SERVER]" Value="[DATABASE_SERVER]" />
</ComboBox>
<Publish Property="LOGON_VALID" Value="0">1</Publish>
</Control>
...

自定义操作:
    [CustomAction]
public static ActionResult EnumerateSqlServers(Session session)
{
if (null == session)
{
throw new ArgumentNullException("session");
}

session.Log("EnumerateSQLServers: Begin");

// Check if running with admin rights and if not, log a message to
// let them know why it's failing.
if (false == HasAdminRights())
{
session.Log("EnumerateSQLServers: " + "ATTEMPTING TO RUN WITHOUT ADMIN RIGHTS");
return ActionResult.Failure;
}

ActionResult result;

DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
DataRow[] rows = dt.Select(string.Empty, "IsLocal desc, Name asc");
result = EnumSqlServersIntoComboBox(session, rows);

session.Log("EnumerateSQLServers: End");
return result;
}

private static ActionResult EnumSqlServersIntoComboBox(Session session, IEnumerable<DataRow> rows)
{
try
{
//Debugger.Break();

session.Log("EnumSQLServers: Begin");

View view = session.Database.OpenView("DELETE FROM ComboBox WHERE ComboBox.Property='DATABASE_SERVER'");
view.Execute();

view = session.Database.OpenView("SELECT * FROM ComboBox");
view.Execute();

Int32 index = 1;
session.Log("EnumSQLServers: Enumerating SQL servers");
foreach (DataRow row in rows)
{
String serverName = row["Name"].ToString();

// Create a record for this web site. All I care about is
// the name so use it for fields three and four.
session.Log("EnumSQLServers: Processing SQL server: {0}", serverName);

Record record = session.Database.CreateRecord(4);
record.SetString(1, "DATABASE_SERVER");
record.SetInteger(2, index);
record.SetString(3, serverName);
record.SetString(4, serverName);

session.Log("EnumSQLServers: Adding record");
view.Modify(ViewModifyMode.InsertTemporary, record);
index++;
}

view.Close();

session.Log("EnumSQLServers: End");
}
catch (Exception ex)
{
session.Log("EnumSQLServers: exception: {0}", ex.Message);
throw;
}

return ActionResult.Success;
}

关于Wix 将项目加载到 ComboBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14455542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com