//动态绑定下拉框
string sql = "select id ,name form B ";
DataTable dt = DBHelper.GetDataTable(sql);
//绑定数据源
this.comboBox1.DataSource = dt;
//绑定要显示的文本的字段
this.comboBox1.DisplayMember = "name";
//绑定真实的值value
this.comboBox1.valueMember = "id";
//弹出下拉框的值或文本
string name = this.comboBox1.Text;
string id = this.comboBox1.SelectdValue.ToString();
MessageBox.Show(name);
时间: 2024-10-23 12:46:10