Reputation: 797
hey guys,Actually i have two comboboxes having same elements but i have used two datasets having same elements.Now when i bind combobox with dataset ,it repeats its elements. Can anyone help me to sort it out?
my code goes like this:
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";
Upvotes: 1
Views: 176
Reputation: 2076
Looking at your code it looks like you want to transfer ownership of an item from one guy to another, using two combos that both populate the same list of data.
You want to exclude the selected item form the destination combo. Try in the foreach loop, to only add an item if it is not the same as the current selected value, something like this (untested)
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()));
}
}
Upvotes: 1