日期:2014-05-18 浏览次数:20930 次
private void Combobox1.SelectedIndexChanged(object sender, EventArgs e) { .....//目标数据源填充另一个Combobox }
------解决方案--------------------
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string[] str = {"广州,深圳","福州,厦门" }; this.comboBox2.Items.Clear(); if (this.comboBox1.Text == "广东") { comboBox2.Items.Add(str[0].Split(',')[0].ToString()); comboBox2.Items.Add(str[0].Split(',')[1].ToString()); } else { comboBox2.Items.Add(str[1].Split(',')[0].ToString()); comboBox2.Items.Add(str[1].Split(',')[1].ToString()); } }
------解决方案--------------------
也可以用绑定的,绑定到数据库里。比如有很多城市和省份就可以用绑定比较好。
//加载业务员下拉框
string strSql = "Select EmployeeID,EmployeeName from Employee";
SqlDataAdapter daEmployee = new SqlDataAdapter(strSql,DataBaseOpen.OpenConnection());
daEmployee.Fill(ds, "Employee");
cmbEmployeeID.ValueMember = "EmployeeID";
cmbEmployeeName.ValueMember = "EmployeeName";
cmbEmployeeID.DataSource = ds.Tables["Employee"];
cmbEmployeeName.DataSource = ds.Tables["Employee"];
//加载客户下拉框
strSql = "Select SupplierID,SupplierName from Supplier";
SqlDataAdapter daClient = new SqlDataAdapter(strSql, DataBaseOpen.OpenConnection());
daClient.Fill(ds, "Supplier");
cmbSupplierID.ValueMember = "SupplierID";
cmbSupplierName.ValueMember = "SupplierName";
cmbSupplierID.DataSource = ds.Tables["Supplier"];
cmbSupplierName.DataSource = ds.Tables["Supplier"];