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
Re: VB.NET 2005 - Copy ListView to ListView
Code:
For Each itm As ListViewItem In lvwTemp.Items
lvwObjectsFound.Items.Add(itm)
Next
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:
Quote:
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.
Re: VB.NET 2005 - Copy ListView to ListView
Quote:
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!
Re: VB.NET 2005 - Copy ListView to ListView
Quote:
Originally Posted by
vinhnd
The fun was had over 3 1/2 years ago.