【发布时间】:2017-05-24 21:17:12
【问题描述】:
我有 3 个comboboxes。
起初我输入了电台的数量。例如11650、13450 和more。
当用户从第一个combobox中选择号码后,自动根据站号在第二个combobox后给出日期。因为每个站的日期都不一样。
我的问题是,如果用户在第二个combobox 中输入数字键以显示日期,我该怎么做?
我的代码是:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string MyConString1 = "SERVER=localhost;" +
"DATABASE=hydrodb;" +
"UID=root;" +
"PASSWORD=;";
MySqlConnection connection1 = new MySqlConnection(MyConString1);
string command1 = "select Dat FROM hydgod where Station=" + comboBox1.SelectedItem.ToString();
MySqlDataAdapter da1 = new MySqlDataAdapter(command1, connection1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
comboBox2.Items.Clear();
comboBox3.Items.Clear();
comboBox2.SelectedItem = -1;
comboBox3.SelectedItem = -1;
foreach (DataRow row in dt1.Rows)
{
string rowz = string.Format("{0}", row.ItemArray[0]);
comboBox2.Items.Add(rowz);
comboBox3.Items.Add(rowz);
}
connection1.Close();
}
【问题讨论】:
-
只是为了澄清:您想根据所选站号使用日期填充第二个
ComboBox? -
是的,我想填充第二个和第三个组合框