Click to See Complete Forum and Search --> : How to delete multiple selection items from a listbox?


mcaron
August 11th, 1999, 08:40 AM
On a form, I have two listbox's. One has items in it, the other is empty. I want to be able to transfer items from one listbox to the other. That part I can do. My problem, is that I want to delete the item, that is being transferd, from it's original listbox. For a single selection, it poses no problem, but if you have a multiple selection enable, it is more complex. I cant use the index after I use the removeitem once, since all the indexes are changed. Example: I have five items (index 0 through 4). I select item 1 & 3. Once I transfer these items to the other listbox, I now want to delete them. If I use the removeitem method once for the item index 1, the other item previously selected (index 3) now becomes index 2! So how can I keep track of all this as I delete items? Is using a while(there are still selected items) conditional loop part of the solution?

Lothar Haensler
August 11th, 1999, 08:45 AM
use a loop like this

for i = list1.listcount-1 to 0 step -1
if list1.selected(i) then
list1.removeitem i
end if
next i



i.e. you loop through the items starting from the end of the list.

chris_boebel
August 11th, 1999, 03:19 PM
loop backwards through the list you are deleting from. This way, your indicies will not change.