I’m doing a HW assignment (as always, don’t indirectly make me a cheater, help me learn!) and I’m having a LOT of trouble with the listbox.
I currently have it able to move/remove single items (fruits selecteditem => myFruits)
However I need to be able to move ALL the items at once, (removing them is easy).
Google hasn’t quite helped, it seems a lot of answers are way too complex for beginner C# or they’re deprecated horribly.
So the question is: how to I transfer the contents of one listbox into another? (Listbox1 name: fruits. Listbox2 name: myFruits)
To move all of the items, try going in reverse order:
A more practical method for moving all of the “selected” items would be to first loop through all of the selected items and add those to the second list box:
And then to remove those items from listBox1, it’s easier to go in reverse order:
The reason for the reverse order is simplicity. If you remove items in forward order, the the “next” index would be off by one, and you would have to manually keep track of your indexes. Hence, going in reverse order avoids that issue.