How to iterate through and delete mutiple selected items from a listview 
Author Message
 How to iterate through and delete mutiple selected items from a listview

        How does one properly iterate through and  delete multiple      
        selected items from a listview ?

                The problem is that if I iterate from 0 to count - 1

                after I delete the first item, the count is
                is now one less than before, and I end up trying to
delete an
                index that is past the bounds of the collection.

                Surely there must be a standard way to do this when
                trying to delete muliple items......

                                thanks,
                                        Tony C.



Sat, 12 Feb 2005 03:15:07 GMT  
 How to iterate through and delete mutiple selected items from a listview
Would iterating from Count-1 down to 0 help with this problem?


Quote:

> How does one properly iterate through and  delete multiple
> selected items from a listview ?

> The problem is that if I iterate from 0 to count - 1

> after I delete the first item, the count is
> is now one less than before, and I end up trying to
> delete an
> index that is past the bounds of the collection.

> Surely there must be a standard way to do this when
> trying to delete muliple items......

> thanks,
> Tony C.



Sat, 12 Feb 2005 03:19:42 GMT  
 How to iterate through and delete mutiple selected items from a listview
How about:

do while item.rows.count
    item.row(0).deleterow
loop


Quote:
> Would iterating from Count-1 down to 0 help with this problem?



> > How does one properly iterate through and  delete multiple
> > selected items from a listview ?

> > The problem is that if I iterate from 0 to count - 1

> > after I delete the first item, the count is
> > is now one less than before, and I end up trying to
> > delete an
> > index that is past the bounds of the collection.

> > Surely there must be a standard way to do this when
> > trying to delete muliple items......

> > thanks,
> > Tony C.



Sat, 12 Feb 2005 05:20:35 GMT  
 How to iterate through and delete mutiple selected items from a listview
I'm not know a lot of things.. but using some as this

Do Until ListViewWithItemsToDelete.SelectedItems.Count = 0
    ListViewWithItemsToDelete.SelectedItems(0).Remove()
Loop

could work??


Quote:
> Would iterating from Count-1 down to 0 help with this problem?



> > How does one properly iterate through and  delete multiple
> > selected items from a listview ?

> > The problem is that if I iterate from 0 to count - 1

> > after I delete the first item, the count is
> > is now one less than before, and I end up trying to
> > delete an
> > index that is past the bounds of the collection.

> > Surely there must be a standard way to do this when
> > trying to delete muliple items......

> > thanks,
> > Tony C.



Sat, 12 Feb 2005 14:20:49 GMT  
 How to iterate through and delete mutiple selected items from a listview
Thanks everyone,
        I did some research on the net and found
that when you have to delete more than one item from a
collection that you have to start at the last one and
iterate backwards to the front  because if you work
from front to back, when you delete itemA, itemB
takes it's place and the next iteration starts on
itemC thereby skipping itemB. I found this on MSDN
after doing some digging.
        So, looks like Marina, you are right.
                        thanks,
                                Tony C.



Quote:
>I'm not know a lot of things.. but using some as this

>Do Until ListViewWithItemsToDelete.SelectedItems.Count = 0
>    ListViewWithItemsToDelete.SelectedItems(0).Remove()
>Loop

>could work??



>> Would iterating from Count-1 down to 0 help with this problem?



>> > How does one properly iterate through and  delete multiple
>> > selected items from a listview ?

>> > The problem is that if I iterate from 0 to count - 1

>> > after I delete the first item, the count is
>> > is now one less than before, and I end up trying to
>> > delete an
>> > index that is past the bounds of the collection.

>> > Surely there must be a standard way to do this when
>> > trying to delete muliple items......

>> > thanks,
>> > Tony C.



Sat, 12 Feb 2005 10:58:25 GMT  
 How to iterate through and delete mutiple selected items from a listview
The code looks like:

dim inti as integer
for inti  = me.listview1.items.count to 1 step -1

        'do the deleting

next inti

  - kind of interesting.....


Quote:
>Thanks everyone,
>    I did some research on the net and found
>that when you have to delete more than one item from a
>collection that you have to start at the last one and
>iterate backwards to the front  because if you work
>from front to back, when you delete itemA, itemB
>takes it's place and the next iteration starts on
>itemC thereby skipping itemB. I found this on MSDN
>after doing some digging.
>    So, looks like Marina, you are right.
>                    thanks,
>                            Tony C.



>>I'm not know a lot of things.. but using some as this

>>Do Until ListViewWithItemsToDelete.SelectedItems.Count = 0
>>    ListViewWithItemsToDelete.SelectedItems(0).Remove()
>>Loop

>>could work??



>>> Would iterating from Count-1 down to 0 help with this problem?



>>> > How does one properly iterate through and  delete multiple
>>> > selected items from a listview ?

>>> > The problem is that if I iterate from 0 to count - 1

>>> > after I delete the first item, the count is
>>> > is now one less than before, and I end up trying to
>>> > delete an
>>> > index that is past the bounds of the collection.

>>> > Surely there must be a standard way to do this when
>>> > trying to delete muliple items......

>>> > thanks,
>>> > Tony C.



Sat, 12 Feb 2005 11:32:10 GMT  
 How to iterate through and delete mutiple selected items from a listview

4ax.com:

Quote:



>>>Do Until ListViewWithItemsToDelete.SelectedItems.Count = 0
>>>    ListViewWithItemsToDelete.SelectedItems(0).Remove()
>>>Loop

>>>> > How does one properly iterate through and  delete multiple
>>>> > selected items from a listview ?

I think Silk is correct, though.  If you only want to delete selected
items, why iterate through the entire collection?  Just iterate through the
SelectedItems collection.

--
If you don't like lunchmeat, please remove it from my e-mail address to
send me an e-mail



Sat, 12 Feb 2005 23:21:27 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. jump listview to the hilight item (selected item)...

2. Why does the previous selected item in a ListView get selected for a short moment

3. ListView control - Keeping selected items looking selected

4. Saving selected Items for Restore after unauthorized Deleting

5. Repost: Deleting last listview item

6. Delete last Listview Item

7. Delete Listview Item

8. DBList Control - selecting item & deleting

9. Deleting ListView items

10. ListBox (w/Checkboxes)....Deleting Multiple-Selected Items

11. Delete selected item with command button?

12. ListView.EnsureVisible near deleted item

 

 
Powered by phpBB® Forum Software