Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a form with a treeview and a listview side by side. When the user selects a row in the listview, I want to expand the corresponding node in the treeview. I have tried the following code but it returns an exception (out of range):

 

Dim tvwIndex as Integer = lvw.FocusedItem.Index

tvw.Nodes(tvwIndex).Expand()

 

This code is in the Click event for the listview.

 

Any help would be appreciated.

  • *Gurus*
Posted

You can't assume the index will be the same. Indexes start at 0 for each group of nodes under a parent. One way of doing this would be to assign a corresponding treenode to the Tag property of a ListViewItem, then casting it when required:

 

DirectCast(lvw.FocusedItem.Tag, TreeNode).Expand()

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...