The SelectedObjectCollection is what is returned by SelectedItems as opposed to
an actual property.
You have a few options here to do this.
Basically you need to make a copy of the selected items and add these to the
destination, then through an iterative process remove the selected items from
the source listbox.
A general flow would be to get the SelectedItems collection into another
collection.
You could then add them individually or use AddRange to add the contents of this
collection to the destination listbox.
Then step through each item in the copy of the collection and use .Items.Remove
to remove each item from the source collection.
However, making a copy of the selected items collection is fairly important.
If you try to use For Each to step through items and remove them at the same
time, this will not work. Because you are removing items from the same list you
are iterating over.
Or you could do a For index on each item in the source listbox and check its
GetSelected(index) property. Then handle them appropriately. If you go backwards
through the list then you could add items to the other and remove items from the
source in one pass.
The actual implementation of the above is up to you as there are a number of
ways to do the same thing.
Gerald
"Dany P. Wu" <da**@nospam.quicksilver.net.nz> wrote in message
news:10***************@drone1-svc-skyt.qsi.net.nz...
Hi everyone,
One of my Windows forms contain two listbox controls, with Add and Remove
buttons between them.
The idea is to allow users to select multiple items from one ListBox, click
the Add button, and the selected items will move to the second ListBox.
I've been trying to use the ListBox.SelectedObjectCollection with no
success. It sounds like the logical thing to use but I can't seem to find
any methods/properties to use in this case. Is there something else I should
be using?
Any comments/suggestions would be greatly appreciated.
Cheers,
Dany.