日期:2014-05-18 浏览次数:20999 次
string[] sp = { "0", "1", "2", "3", "4" };// 比如 串口 可选列表
string[] bitraye = { "5", "6", "7", "8", "9" };// 比如 波特率 可选列表
this.comboBox1.DataSource = sp;
this.comboBox2.DataSource = bitraye;
this.comboBox1.SelectedItem = "1";// 数据库查询得出的 串口 值赋予 comboBox1
this.comboBox2.SelectedItem = "8";// 数据库查询得出的 波特率 值赋予 comboBox1
// 注册 SelectedIndexChanged 事件,两个 comboBox 的事件方法指向同一个
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
string sp = (string)this.comboBox1.SelectedItem;
string bitrate = (string)this.comboBox2.SelectedItem;
// 更新数据库
}
------解决方案--------------------
通过下拉框改变事件进行更新数据库,加载时comBox1.datasource=数据库查选的数据;
comboBox1.SelectedText=数据库字段