combobox数据绑定之后SelectedIndexChanged事件无法触发咋办?
功能是窗体运行的时候从数据库加载数据绑定到combobox 然后通过下拉框选择一个院系 listbox中可以显示该院系对应的专业 可是运行的时候怎么改变下拉框的选项 listbox显示的还是第一个院系对应的专业 怎么破? 新手求教育~~
这是窗体加载的代码:
private void fmAddStudent_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
DataTable table = SqlHelper.DataTable("select * from T_YuanXi where Pid = 0");
foreach (DataRow row in table.Rows)
{
YuanXi yx = new YuanXi();
yx.Id = (int)row["Id"];
yx.Name = (string)row["Name"];
yuanxi.Add(yx);
}
cmbYuanXi.DataSource = yuanxi;
cmbYuanXi.DisplayMember = "Name";
cmbYuanXi.ValueMember = "Name";
}
这是combobox的事件代码:
private void cmbYuanXi_SelectedIndexChanged(object sender, EventArgs e)
{
YuanXi yx = (YuanXi)cmbYuanXi.SelectedItem;
DataTable table = SqlHelper.DataTable("select * from T_YuanXi where Pid = @Id", new SqlParameter("@Id", yx.Id));
foreach (DataRow row in table.Rows)
{
YuanXi yx1 = new YuanXi();
yx1.Id = (int)row["Id"];
yx1.Name = (string)row["Name"];
yuanxi1.Add(yx1);
}
listZhuanYe.DataSource = yuanxi1;
listZhuanYe.DisplayMember = "Name";
listZhuanYe.ValueMember = "Name";
}