|
-
Jan 23rd, 2008, 01:56 PM
#1
Thread Starter
Hyperactive Member
VB.NET 2005 - Copy ListView to ListView
Hi,
VB.NET 2005
Anyone has a quick way to copy a listview to a new listview?
It tried the following, but it crashes ..
Dim arrTemp(lvwTemp.Items.Count) As ListViewItem
lvwTemp.Items.CopyTo(arrTemp, 0)
lvwObjectsFound.Items.AddRange(arrTemp)
Thanks for helping.
Structure of lvwTemp is:
With lvwTemp
.Clear()
.Columns.Add("Nom", 400, HorizontalAlignment.Left)
.Columns.Add("Type", 200, HorizontalAlignment.Left)
End With
-
Jan 23rd, 2008, 02:05 PM
#2
Re: VB.NET 2005 - Copy ListView to ListView
Code:
For Each itm As ListViewItem In lvwTemp.Items
lvwObjectsFound.Items.Add(itm)
Next
-
Jan 23rd, 2008, 09:42 PM
#3
Re: VB.NET 2005 - Copy ListView to ListView
You can't add a ListViewItem to a ListView when it's already in another. You need to call the Clone method of each item to create a copy you can then add to the other ListView. As the documentation for the ListViewItem.Clone method says:
You can use this method to create a new instance of the ListViewItem class based on an existing item. Even the subitems of the item being cloned are specified for the new version. This feature is useful if you want to reuse a ListViewItem in more than one ListView control.
-
Aug 25th, 2011, 03:43 AM
#4
New Member
Re: VB.NET 2005 - Copy ListView to ListView
 Originally Posted by Tom Sawyer
Code:
For Each itm As ListViewItem In lvwTemp.Items
lvwObjectsFound.Items.Add(itm.Clone())
Next
http://msdn.microsoft.com/en-us/libr...tem.clone.aspx
Have fun!
-
Aug 25th, 2011, 08:10 AM
#5
Re: VB.NET 2005 - Copy ListView to ListView
 Originally Posted by vinhnd
The fun was had over 3 1/2 years ago.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|