Removing items from ListView en masse 
Author Message
 Removing items from ListView en masse

I'm using VB4EE and I have a ListView with about 55 items.  What I want to
be able to do is "mass move" the items in the ListView to another ListView.

My pseudocode is:

For Each Item in ListView1
Add the item to ListView2
Remove the item from ListView1

The number of items in ListView1 can vary from 1 to 32767, so I can't just
hardcode in 55.

I appreciate your help.

--

Quote:
} // Robert

* "The opinions expressed herein are solely the author's and are not
necessarily the opinions of USAA"



Sat, 20 Nov 1999 03:00:00 GMT  
 Removing items from ListView en masse

hi robert,

don't remove each item of ListView1. use the clear-method.
and use the with-construct to add the items

With ListView2.ListItems
    For Each Item in ListView1
        Set itmX = .Add()
    Next
End With

ListView1.ListItems.Clear

hope this helps
regards, pietro



Quote:
> I'm using VB4EE and I have a ListView with about 55 items.  What I want
to
> be able to do is "mass move" the items in the ListView to another
ListView.

> My pseudocode is:

> For Each Item in ListView1
> Add the item to ListView2
> Remove the item from ListView1

> The number of items in ListView1 can vary from 1 to 32767, so I can't
just
> hardcode in 55.

> I appreciate your help.

> --
> } // Robert
> * "The opinions expressed herein are solely the author's and are not
> necessarily the opinions of USAA"




Sun, 21 Nov 1999 03:00:00 GMT  
 Removing items from ListView en masse

hi robert,

Quote:
> On the For Each Item In ListView1, I receive:

the syntax is for each OBJECT in COLLECTION and the collection is
ListView1.ListItems (ListView1 isn't a collection)

if you loop through the collection, you can't modify it (remove items).
runtime error (35606 Control's collection has been modified)

look the code below, this is a possible solution for your problem.
the code stores all selected items in a listitem-array.
loop through the listitem-array, add the items to listview2 and remove them
from listview1.

    Dim i As Integer
    Dim itmX As ListItem
    Dim arrX() As ListItem

    i = 0
    ReDim arrX(0)

    For Each itmX In ListView1.ListItems
        If itmX.Selected Then
            i = i + 1
            ReDim Preserve arrX(UBound(arrX) + 1)
            Set arrX(i) = itmX
        End If
    Next

    With ListView2.ListItems
        For i = 1 To UBound(arrX)
            Set itmX = .Add(, , arrX(i).Text)
            itmX.Key = arrX(i).Key
            ListView1.ListItems.Remove (arrX(i).Index)
        Next i
    End With

hope this helps.
regards, pietro    



Quote:
> On the For Each Item In ListView1, I receive:

> "Object Doesn't Support This Property or Method"

> If I remove the Dim Item statement, I receive:

> "Variable Not Defined"

> Also, ListView1.MultiSelect = True, so not all of the items will be
removed
> when the user adds them en masse to ListView2.

> So it's like:

> For Each *Selected* Item in ListView1
> Add item to ListView2
> Remove Item from ListView1

> Any ideas?

> Robert



> : hi robert,
> :
> : don't remove each item of ListView1. use the clear-method.
> : and use the with-construct to add the items
> :
> : With ListView2.ListItems
> :     For Each Item in ListView1
> :         Set itmX = .Add()
> :     Next
> : End With
> :
> : ListView1.ListItems.Clear
> :
> : hope this helps
> : regards, pietro
> :



Mon, 22 Nov 1999 03:00:00 GMT  
 Removing items from ListView en masse

Coming in late on theis conversation, if the message title is accurate =
(removing listview ites all at once), then just use:

  Const LVM_FIRST =3D &H1000
  Const LVM_DELETEALLITEMS =3D (LVM_FIRST + 9)

  Dim r As Long
  r =3D SendMessage(ListView1.hwnd, LVM_DELETEALLITEMS, 0, 0)

--=20
Randy Birch, MVP
Visual Basic


Moderator, Fidonet Visual Basic Programmer's Conference

http://home.sprynet.com/sprynet/rasanen/
VBnet, The Visual Basic Developers Resource Centre



: On the For Each Item In ListView1, I receive:
:=20
: "Object Doesn't Support This Property or Method"
:=20
: If I remove the Dim Item statement, I receive:
:=20
: "Variable Not Defined"
:=20
: Also, ListView1.MultiSelect =3D True, so not all of the items will be =
removed
: when the user adds them en masse to ListView2.
:=20
: So it's like:
:=20
: For Each *Selected* Item in ListView1
: Add item to ListView2
: Remove Item from ListView1
:=20
: Any ideas?
:=20
: Robert
:=20

in

: : hi robert,
: :=20
: : don't remove each item of ListView1. use the clear-method.
: : and use the with-construct to add the items=20
: :=20
: : With ListView2.ListItems
: :     For Each Item in ListView1
: :         Set itmX =3D .Add()
: :     Next
: : End With
: :=20
: : ListView1.ListItems.Clear
: :=20
: : hope this helps
: : regards, pietro
: :=20
:=20
:



Sat, 27 Nov 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Removing items from ListView en masse

2. ListView Control - Removing selected items from the list

3. Removing an item from a listview

4. Removing an item from a ListView

5. help adding and removing items from a listview

6. Q: How to get rid of ListView flicker when adding/removing items

7. SHFileOp and removing corresponding items from ListView

8. removing items from a listview

9. Remove Selected item in ListView Control

10. ListView items remain indented after removing icons

11. How to remove items in a listview?

12. Remove selected items from a listview control in report format

 

 
Powered by phpBB® Forum Software