在 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}里绑定值
public void InsertComShopID(ComboBox cb)
{
cb.Items.Clear();
SqlCommand cmd = new SqlCommand("select name from A ","');
SqlDataReader sdr =cmd.ExecuteReader();
while (sdr.Read())
{
cb.Items.Add(sdr[0].ToString());
}
sdr.Close();
}
或扩展WinForm的ComboBox 参考
{
}里绑定值
public void InsertComShopID(ComboBox cb)
{
cb.Items.Clear();
SqlCommand cmd = new SqlCommand("select name from A ","');
SqlDataReader sdr =cmd.ExecuteReader();
while (sdr.Read())
{
cb.Items.Add(sdr[0].ToString());
}
sdr.Close();
}
或扩展WinForm的ComboBox 参考
在第一个选中某一项的时候,刷新第二个
两个刷新的方法是一样的,只是查询的语句不同
同意,你调用SelectedIndexChanged方法就可以实现。
if (comboBox2.Text.Trim() != "")
{
using (SqlConnection sconn = SQLHelp.GetConnection())
{
sconn.Open();
string sql = "select Item_id ,Item_name from Item_table where Eng_id=" + comboBox2.SelectedValue.ToString() + ""; SqlDataAdapter adp = new SqlDataAdapter(sql,sconn);
adp.Fill(ds, "Item_table");无法绑定由多个部分组成的标识 符 "System.Data.DataRowView"。
if (ds.Tables["Item_table"].Rows.Count != 0)
{
comboBox3.DisplayMember = "Item_name";
comboBox3.ValueMember = "Item_id";
comboBox3.DataSource = ds.Tables["Item_table"].DefaultView;
}
else
{
comboBox3.DataSource = null;
comboBox3.SelectedIndex = -1;
}
sconn.Close();
}
}
else
{
comboBox3.DataSource = null;
comboBox3.SelectedIndex = -1;
}
}