Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I click the remove button from Listbox2 the selected item is moved to listbox1.
My code as follows;
C#
Listbox2.Items.Add(listbox1.SelectedItem);

I tried the below code it is working.

I would like to check two condition.
1. From listbox1 hen I add item and move to listbox2 and click the remove button.Listbox2 item to be removed.

2. From listbox2 when I click the remove button that selected item from listbox2 move to listbox1.

When I removing the listbox2 item to listbox1 that time listbox2 selected item wont be there to be removed.

How to do the above both condition in single Remove Button.

please help me. how can I do.
Posted
Updated 27-Jan-13 2:14am
v3
Comments
Suresh Dasari's 24-Jan-13 4:52am    
confused

adding listbox1 item to listbox2 item
Listbox2.Items.Add(listbox1.SelectedItem);

these are confusing
1. from listbox1 when i add item and move to listbox2 and click the remove button.Listbox2 item to be removed.

2. from listbox2 when i click the remove button that selected item from listbox2 move to listbox1.

when i removing the listbox2 item to listbox1 that time listbox2 selected item wont be there to be removed.

can you post in brief.
P_Dash 24-Jan-13 4:55am    
This can be done.But with 1 single Button it will be difficult to handle.
So better if you use 2 Buttons then using jQuery it can be possible.
CHill60 24-Jan-13 17:02pm    
jQuery? What on earth for?
CHill60 24-Jan-13 17:03pm    
So are you just saying that when you click the button the selected row in either listbox is moved to the other one?

1 solution

this is the answer

but you must ignore the exceptions


C#
try
           {
               listBox2.Items.Add(listBox1.SelectedItem);
               listBox1.Items.Remove(listBox1.SelectedItem);
               listBox1.ClearSelected();
               //

           }
           catch(Exception ee){}
           try
           {
               listBox1.Items.Add(listBox2.SelectedItem);
               listBox2.Items.Remove(listBox2.SelectedItem);
               listBox2.ClearSelected();
           }
           catch(Exception ee){}



let me know if you have any question with code
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900