georgepatotk Posted April 15, 2005 Posted April 15, 2005 I want to copy the whole list of a listview to another without using iteration statement because it could be time consuming if my data volume is large. I had tried lv1 = lv2, this doesn't seems to work correctly because lv2 is created in other class. I wish to do something like lv1.Items = lv2.items Please give me a clue to do this with iteration control. Thanks in advance.. Quote George C.K. Low
Leaders snarfblam Posted April 15, 2005 Leaders Posted April 15, 2005 The Items property is readonly, so of course you can't do lv2.Items=lv1.Items. You can't do lv1 = lv2 because then your just setting your variable, lv2, to point to a whole different listview: lv1, not a different set of listview items. This is a way you could copy list view items from one listview to another... 1 'Assuming you have two listviews, named lv1 and lv2... 2 Dim MyItems As ListViewItem() = New ListViewItem(lv1.Items.Count-1) 3 lv1.Items.CopyTo(MyItems) 4 lv1.Items.Clear 'You CANT have a listview item in more than one listview at a time 5 lv2.Items.AddRange(MyItems) Notice line 4. If you want to have the items appear in both listviews simultaneously, as far as I can see, you must iterate through them and clone each one. And if you don't need them in both listviews at once (if, for instance, the listviews are on separate forms and only one is displayed at a time) you could conceivably remove the listview from one form and add it to the other. Another thing you could do is just populate both listviews at the same time. If you can't do any of those, you can always use for loop and slap up a progress bar. Quote [sIGPIC]e[/sIGPIC]
georgepatotk Posted April 15, 2005 Author Posted April 15, 2005 Thanks, this piece of code is realy helpful... Quote George C.K. Low
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.