【发布时间】:2014-05-27 11:39:40
【问题描述】:
private void PopulateComboBox()
{
SqlConnection connection;
SqlCommand command;
SqlDataReader reader;
DataTable dt;
using (connection = new SqlConnection("connection string here"))
{
using (command = new SqlCommand("sql query here", connection))
{
connection.Open();
using (reader = command.ExecuteReader())
{
dt = new DataTable();
dt.Load(reader);
ComboxBox1.ValueMember = "col1";
ComboxBox1.DisplayMember = "col2";
ComboxBox1.DataSource = dt;
}
connection.Close();
}
}
}
上面的代码工作正常。但是,我想在 ComboBox1 的索引 0 处添加一个静态条目以及来自数据库的上述动态条目。静态索引 0 的值应该是“选择一个值”。
如何在 ComboBox 中组合静态和动态数据?
【问题讨论】:
标签: c# c#-4.0 .net-4.0 visual-studio-2013 vsto