My windows form contains two listboxes. Listbox1 contains some items in it and listbox2 is empty. When I press a button on the form, then multiple selected items from listbox1 should be removed from Listbox1 and copied to Listbox2.
I tried with foreach loop on listbox1.SelectedItems but it removes only 1 item from list.
Anyone has solution or code for this?
Its Works.
This is my method:
For VS2005 I user something similar as I couldn't use .selectedIndices
I did this using using the CopyTo method to copy the items to an array the length of the count of selected items and then looped around that array removing each corresponding item from ListBox1.
You could do all in a single loop. You should use a simple for and loop backwards on SelectedIndices:
you must store The values, you want to delete in other palce and then delete them from List,Here is sample code: