I am experiencing a strange problem with my ListViews. I have two listviews
on a form. One of the listview contains a master set of data and the other
will contain a subset of that data.
I have instantiated two separate listviews and for some reason when ever I
copy an item from one list view to another (using a simple ArrayList as my
temporary work area on the subset data), I get an error as follows:
An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll
Additional information: Cannot add or insert the item 'testitem' in more
than one place. You must first remove it from its current location or clone
it.
But, If I perform a listview.Items.Clear() before moving data into the
second listview....everything is fine. But I want the data in both
places.......
I thought this could have been some sort of reference issue....but since I
have two separate instances of ListView I don't see how....but at this point
I am stuck.
Any help would be appreciated. Thank you!
----------------------------------------------------
Jeff Slapp
Fairway Consulting Group, Inc.
Ft Lauderdale, FL
www.fcgroup.us
----------------------------------------------------
Hi,
To copy a ListViewItem from ListView1 to ListView2, rather than using:
ListView2.Items.Add(ListView1.Items.Item(0))
which causes the exception that you mention, use this instead:
ListView2.Items.Add(DirectCast(ListView1.Items.Item(0).Clone,
ListViewItem))
since a single instance of a ListViewItem can not belong to 2 listviews, you
need a clone.

Signature
Carlos J. Quintero
MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code and design much faster.
http://www.mztools.com
>I am experiencing a strange problem with my ListViews. I have two listviews
>on a form. One of the listview contains a master set of data and the other
[quoted text clipped - 26 lines]
> www.fcgroup.us
> ----------------------------------------------------
Jeff Slapp - 03 Jan 2005 15:59 GMT
That worked. Thanks!
> Hi,
>
[quoted text clipped - 40 lines]
>> www.fcgroup.us
>> ----------------------------------------------------