开发者

combo box selected index changed all comboboxes are changed

I have two combo boxes in my form. i have binded these two with different database tables 开发者_如何学Cbut with the same display member and some of data are repeated. When i change the index of first combo box ,the second combo box index also changed.

how to clear this problem. please any one give me the solution

Thanks

//dt1---> a b c d
//dt2---> x c a y
 cmb_STable.SelectedIndex = -1;
            cmb_STable.DisplayMember = "tablename";
            cmb_STable.DataSource = dt1;
 cmb_mTable.SelectedIndex = -1;
            cmb_mTable.DisplayMember = "tablename";
            cmb_mTable.DataSource = dt2;

// if cmb_mTable_SelectedIndexChanged with a , the cmb_sTable also changed with a


Shot in the dark:

I assume you are using ADO.Net to databind the comboboxes. Depending on the API you will either have a bindingsource or a CurrencyManager in the background which has a copy of the databound list and a pointer to the current item.

My guess is that you have bound both lists to this datasource via the same CurrencyManager/BindingSource and moving it on one control moves it on the other.

You need to add a new BindingSource or currencymanager to stop this behaviour.


Your code still doesn't show everything.

It looks like there is a Databinding for the SelectedValue for both boxes. If they are bound to the same item (copy pasted?) , then that explains your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜