Moving to top of TreeView after ExpandAll()
Greetings:
I am trying to move to the top of my TreeView control after expanding all. This means that I should see the highlighted node (0) after the ExpandAll is done. But nothing I have tried does this.
Bellow is my code:
Private Sub btnExpandAll_Click(sender As Object, e As EventArgs) Handles btnExpandAll.Click
trvMasterFormat.Focus()
trvMasterFormat.ExpandAll()
trvMasterFormat.SelectedNode = trvMasterFormat.Nodes(0)
trvMasterFormat.Refresh()
End Sub
Any help in this regard woulkd be greatly appreciated.
Thanks!
Re: Moving to top of TreeView after ExpandAll()
Try this:
Code:
Private Sub btnExpandAll_Click(sender As Object, e As EventArgs) Handles btnExpandAll.Click
trvMasterFormat.ExpandAll()
trvMasterFormat.SelectedNode = trvMasterFormat.Nodes(0)
trvMasterFormat.Select()
End Sub
Re: Moving to top of TreeView after ExpandAll()
stanav thanks but end results is the tree view control is still showing the last node and not the first
Re: Moving to top of TreeView after ExpandAll()
Quote:
Originally Posted by
lhasha
stanav thanks but end results is the tree view control is still showing the last node and not the first
I don't quite understand what you mean exactly... The code works fine for me. Can you post a screen shot to show what you mean? And by the way, what, if any, treeview events are you handling?
2 Attachment(s)
Re: Moving to top of TreeView after ExpandAll()
While I know that setting focus is not the correct term when referring to nodes, that is exactly what I am seeking. After expanding all, the TreeView is showing the very end of the list as shown below:
Attachment 97379
But when scrolling up, the first node is selected as shown below:
Attachment 97381
What I want is to have visual focus after the expand all as shown in the second image.
Re: Moving to top of TreeView after ExpandAll()
Code:
TreeView.TopNode.EnsureVisible
Something like that anyway.
Re: Moving to top of TreeView after ExpandAll()
Grimfort: Thanks but same results :(
Re: Moving to top of TreeView after ExpandAll()
This seems like one of 'THOSE' issues that will drive me crazy YIKES!
Re: Moving to top of TreeView after ExpandAll()
Quote:
Originally Posted by
stanav
I don't quite understand what you mean exactly... The code works fine for me. Can you post a screen shot to show what you mean? And by the way, what, if any, treeview events are you handling?
No treeview events being handled
Re: Moving to top of TreeView after ExpandAll()
Quote:
Originally Posted by
stanav
I don't quite understand what you mean exactly... The code works fine for me. Can you post a screen shot to show what you mean? And by the way, what, if any, treeview events are you handling?
No treeview events being handled
Re: Moving to top of TreeView after ExpandAll()
The following code must work
vb Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TreeView1.ExpandAll()
TreeView1.Nodes(0).EnsureVisible()
TreeView1.SelectedNode = TreeView1.Nodes(0)
TreeView1.Focus()
End Sub
If it isn't work inside your project, try it with new project.
Re: Moving to top of TreeView after ExpandAll()
Quote:
Originally Posted by
4x2y
The following code must work
vb Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TreeView1.ExpandAll()
TreeView1.Nodes(0).EnsureVisible()
TreeView1.SelectedNode = TreeView1.Nodes(0)
TreeView1.Focus()
End Sub
If it isn't work inside your project, try it with new project.
4x2y! BINGO! Thanks and thanks to all others who contributed!
Re: Moving to top of TreeView after ExpandAll()
TreeView1.Nodes(0).EnsureVisible()
Is no different from
TreeView.TopNode.EnsureVisible
So I have to assume it is the Focus you are interested in seeing, that is the blue highlight, in which case check out this property, which may help in future.
Re: Moving to top of TreeView after ExpandAll()
Quote:
TreeView1.Nodes(0).EnsureVisible()
Is no different from
TreeView.TopNode.EnsureVisible
They are totally different, TreeView1.Nodes(0) points to the first node while TreeView.TopNode points to the first visible node, to know the difference use
vb Code:
Debug.Print("TopNode is " & TreeView1.TopNode.Text)
Debug.Print("Nodes(0) is " & TreeView1.Nodes(0).Text)
The TopNode property is changing each time you scroll the tree.