我的代码是这样的:
DataSet ds_PromotionDesignation = new DataSet();
ds_PromotionDesignation = EPI.comboDeg();
cmbPromotionDesignationFrom.DataSource = ds_PromotionDesignation.Tables[0];
cmbPromotionDesignationFrom.DisplayMember = "DEG_NAME";
cmbPromotionDesignationFrom.ValueMember = "DEG_ID";
cmbPromotionDesignationFrom.SelectedIndex = -1;
DataSet ds_PromotionDesignationTo = new DataSet();
ds_PromotionDesignationTo = EPI.PromotionDesignationTo();
foreach (DataRow row in ds_PromotionDesignationTo.Tables["tbl_org_Desg"].Rows)
{
myAL.Add(new USState(row["DEG_ID"].ToString(),row["DEG_NAME"].ToString()));
}
cmbPromotionDesignationTo.DataSource = myAL;
cmbPromotionDesignationTo.DisplayMember = "DEGNAME";
cmbPromotionDesignationTo.ValueMember = "DEGID";
答案 0 :(得分:1)
查看您的代码,看起来您希望将项目的所有权从一个人转移到另一个人,使用两个组合填充相同的数据列表。
您想要从目标组合中排除所选项目。尝试使用foreach循环,只添加一个项目,如果它与当前选择的值不同,就像这样(未经测试)
foreach (DataRow row in ds_PromotionDesignationTo.Tables["tbl_org_Desg"].Rows)
{
if ((int)row["DEG_ID"] != (int)cmbPromotionDesignationFrom.SelectedValue)
{
myAL.Add(new USState(row["DEG_ID"].ToString(), row["DEG_NAME"].ToString()));
}
}