Results 1 to 14 of 14

Thread: Moving to top of TreeView after ExpandAll()

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Posts
    15

    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!

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Posts
    15

    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

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Moving to top of TreeView after ExpandAll()

    Quote Originally Posted by lhasha View Post
    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?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Posts
    15

    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:
    Name:  Example1.jpg
Views: 4396
Size:  25.5 KB

    But when scrolling up, the first node is selected as shown below:
    Name:  Example2.jpg
Views: 4318
Size:  23.4 KB

    What I want is to have visual focus after the expand all as shown in the second image.

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Moving to top of TreeView after ExpandAll()

    Code:
    TreeView.TopNode.EnsureVisible
    Something like that anyway.

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Posts
    15

    Re: Moving to top of TreeView after ExpandAll()

    Grimfort: Thanks but same results

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Posts
    15

    Re: Moving to top of TreeView after ExpandAll()

    This seems like one of 'THOSE' issues that will drive me crazy YIKES!

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Posts
    15

    Re: Moving to top of TreeView after ExpandAll()

    Quote Originally Posted by stanav View Post
    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

  10. #10

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Posts
    15

    Re: Moving to top of TreeView after ExpandAll()

    Quote Originally Posted by stanav View Post
    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

  11. #11
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Moving to top of TreeView after ExpandAll()

    The following code must work
    vb Code:
    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2.         TreeView1.ExpandAll()
    3.         TreeView1.Nodes(0).EnsureVisible()
    4.         TreeView1.SelectedNode = TreeView1.Nodes(0)
    5.         TreeView1.Focus()
    6.     End Sub


    If it isn't work inside your project, try it with new project.



  12. #12

    Thread Starter
    New Member
    Join Date
    Mar 2013
    Posts
    15

    Re: Moving to top of TreeView after ExpandAll()

    Quote Originally Posted by 4x2y View Post
    The following code must work
    vb Code:
    1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    2.         TreeView1.ExpandAll()
    3.         TreeView1.Nodes(0).EnsureVisible()
    4.         TreeView1.SelectedNode = TreeView1.Nodes(0)
    5.         TreeView1.Focus()
    6.     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!

  13. #13
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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.

  14. #14
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Moving to top of TreeView after ExpandAll()

    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:
    1. Debug.Print("TopNode is " & TreeView1.TopNode.Text)
    2.         Debug.Print("Nodes(0) is " & TreeView1.Nodes(0).Text)

    The TopNode property is changing each time you scroll the tree.
    Last edited by 4x2y; Mar 5th, 2013 at 07:57 PM.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width