By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,111 Members | 1,652 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,111 IT Pros & Developers. It's quick & easy.

Using Treeview tag property to hold ListViewItemCollection

P: n/a
Hello,

I have a TreeView I'm using to navigate through various options shown in a
ListView. I want to use the SelectedNode.Tag property to hold the items in my
ListView.

Everything is working great, except...

Private Sub tvBookmarks_BeforeSelect(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs) Handles tvBookmarks.BeforeSelect
If Not tvBookmarks.SelectedNode Is Nothing Then
tvBookmarks.SelectedNode.Tag = lvBookmarkDetail.Items
lvBookmarkDetail.Items.Clear()
End If
End Sub

Private Sub tvBookmarks_AfterSelect(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles tvBookmarks.AfterSelect
If Not e.Node.Tag Is Nothing Then
If CType(e.Node.Tag, ListView.ListViewItemCollection).Count > 0
Then
For Each li As ListViewItem In CType(e.Node.Tag,
ListView).Items
lvBookmarkDetail.Items.Add(li)
Next
End If
End If
End Sub

As you can see, before the new node is selected, I take the currently
selected node and save the listview information to it. Well, I try to. Except
in this instance, it just makes a pointer to the current data in listview,
and doesn't actually save a copy of it.

Now, I realize the Item property has a Clone object, but is there a way to
instaniate a new ListViewItemCollection object and then save that data to my
Node.Tag property?

Seems like inefficient code to loop through each item in a For Each to clone
it, and even then I'm stuck because I can't initialize a new
ListViewItemCollection object... or at least it won't let me when I try:

Dim lvic as New ListView.ListViewItemCollection

Because the owner is required... and I have no owner.

I've also seen some indication of the CopyTo method for this purpose as
well... but seeing as how I've been trying this all afternoon now, and it's
almost time to go, this method doesn't make sense to me at the moment.

If anyone could help shed some light on this subject for me, that would be
awesome. Thanks.

- Andre
Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.