日期:2014-05-20  浏览次数:20892 次

关于comboBox的小问题
我有一个表,有组名,人员名字段
两个comboBox
comboBox1显示组名comboBox2显示人员名
要comboBox1里小组变换时comboBox2人员也跟着变
这个应该怎么做啊

------解决方案--------------------
当combobox1中SelectedIndexChanged 时,选出新人员集合,重新绑定combobox2的DataSource
------解决方案--------------------
设置ComboBox1的SelectedIndexChanged事件
当SelectedIndex改变时 设置ComboBox2的SelectedIndex
------解决方案--------------------
private void InstallServiceForm_Load(object sender, EventArgs e)
{
DataTable depdt = new DataTable();
SelectDepDDL.DataSource = depdt;
SelectDepDDL.DisplayMember = "DepName ";
SelectDepDDL.ValueMember = "DepID ";
}

private void SelectDepDDL_SelectedIndexChanged(object sender, EventArgs e)
{
string SelectedDepID = SelectDepDDL.SelectedValue.ToString();
if (SelectedDepID != null && SelectedDepID != " ")
{
if (SelectedDepID == "System.Data.DataRowView ")
{
SelectedDepID = DefaultDepID;
}

DataTable rdt = new DataTable();
if (rdt.Rows.Count > 0)
{
DefaultRecordID = rdt.Rows[0][0].ToString();
}
SelectRecordDDL.DataSource = rdt;
SelectRecordDDL.DisplayMember = "RecordName ";
SelectRecordDDL.ValueMember = "RecordID ";
}
}
------解决方案--------------------
glacier111,正解﹗