470,625 Members | 2,059 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,625 developers. It's quick & easy.

How to copy one listview to another. Hopefully this can help someone ;-)

Hi guys,
I stuffed around with this for a whole day, searching the groups
and trying different methods. So when I finally came up with a solution
I thought I would share it, as it could save someone all the stuffing
round I had to do. Now I don't know if this will solve everyone's
listview copy situation, but it worked for me.

Here is the code:

ListViewItems[] LVIARRY_CopiedListViewItems = new
ListViewItems[LV_FirstListView.Items.Count];

for (int INT_Count=0; INT_Count < LVIARRY_CopiedListViewItems.Length;
INT_Count++)
{
LVIARRY_CopiedListViewItems[INT_Count] =
(ListViewItem)LV_FirstListView.Items[INT_Count].Clone();
}

LV_SecondListView.Items.AddRange(LVIARRY_CopiedLis tViewItems);

Scott.

Nov 17 '05 #1
2 4454
did you try the Array.Copy() method work on this? Or does this create
a new instance of an array with references to the original ListItems?

Nov 17 '05 #2
James,
I did try that method, but I had the same problem as the poster
called "CaffeineRush" in this post:
---------------------------------------------------
http://groups.google.com/group/micro...294ffc72f62442

I go the same:
---------------------------------------------------
System.ArgumentException error in system.windows.forms.dll:

Additional information: Cannot add or insert the item 'filename.jpg' in
more than one place. You must first remove it from its current location
or clone it.
---------------------------------------------------
After a bit more research I then found this thread:
---------------------------------------------------
http://groups.google.com/group/micro...otnet.*&rnum=2

See where the poster "laurmo" says:
---------------------------------------------------
Basically it then turns out that the ListViewItemCollection is then
just a reference to the ListView.Items data and any operation done on
one is
reflected on the other.
---------------------------------------------------

I am open to new ideas however?

Scott.

ja*********@gmail.com wrote:
did you try the Array.Copy() method work on this? Or does this create
a new instance of an array with references to the original ListItems?


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by MikeY | last post: by
3 posts views Thread by MikeY | last post: by
1 post views Thread by MikeY | last post: by
9 posts views Thread by Devron Blatchford | last post: by
6 posts views Thread by Beginner | last post: by
1 post views Thread by MikeY | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.