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

L

ltnats

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_CopiedListViewItems);

Scott.
 
J

james.novak

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?
 
L

ltnats

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/micr...osoft.public.dotnet.*&rnum=2#b6294ffc72f62442

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top