expand a treeview at a particular node

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,
Say I have the following Treeview :

N1
|-N11
|-N12
|-N121
|-N122
N2
|-N21
|-N22
|-N221
|-N222
N3

N1, N2 and N3 are collapsed so my tree is enterely collapsed.
Now if N2 is expanded and N222 is selected, when the user clicks on a
button that should delete N222 and the tree should be refreshed and
expanded to N221, which is the previous node (if there was no previous
node, then N22 would be selected - only Nxxx nodes can be deleted).
I know how to get the level of a node :

While Not node Is Nothing
node = node.Parent
level += 1
End While

as well as its index. But N222 and N122 have the same level and index,
so how can I know to which node I should expand my tree ?

Some code would be very welcome !

Thx for your help.

Sam
 
Hi,

With node.parent
.EnsureVisible ' make sure the node is visible
.Expand ' Show all of it children
end with

http://msdn.microsoft.com/library/d...ystemwindowsformstreenodeclassexpandtopic.asp

http://msdn.microsoft.com/library/d...ndowsformstreenodeclassensurevisibletopic.asp


Ken
------------------
Hi,
Say I have the following Treeview :

N1
|-N11
|-N12
|-N121
|-N122
N2
|-N21
|-N22
|-N221
|-N222
N3

N1, N2 and N3 are collapsed so my tree is enterely collapsed.
Now if N2 is expanded and N222 is selected, when the user clicks on a
button that should delete N222 and the tree should be refreshed and
expanded to N221, which is the previous node (if there was no previous
node, then N22 would be selected - only Nxxx nodes can be deleted).
I know how to get the level of a node :

While Not node Is Nothing
node = node.Parent
level += 1
End While

as well as its index. But N222 and N122 have the same level and index,
so how can I know to which node I should expand my tree ?

Some code would be very welcome !

Thx for your help.

Sam
 
actually it seems to work by doing :

tvMain.SelectedNode = m_savedNode (m_savedNode being the node that was
previously selected before collapsing the tree) Now since m_savedNode
is meant to be deleted, I have to figure out how to select the previous
node (or that node's parent)
 
Back
Top