views:

84

answers:

3

am using two combobox in my C# .net windows application like combobox1 & combobox2(two combobox contain same items) if am choosing any items in combobox1 i need to hide that value in combobox2. Am having problem in this

A: 

I guess you want the same index to be selected in the second combobox as you select in the first.

So on the SelectedIndexChanged event of combobox1 add this code:

combobox2.SelectedIndex = combobox1.SelectedIndex;

thelost
+1  A: 

The simplest solution is to handle SelectedItemChanged on the first combo box and re-generate the list of Items for the second combo box so that the selected item in the first is excluded. This should perform alright if you don't have a large number of items. An additional boundary case to consider:

  • If you later change the selection in the first combo box to match what was selected in the second combo box, you might want to clear and reset the second combo box. You can handle this case in the same SelectedItemChanged event handler on the first combo box.
Dan Bryant
A: 

The easiest but perhaps not the cleanest:

Just repopulate combobox2 based on what's not in combobox1 every time an item is selected in combobox1.

fishhead