Consulting

Results 1 to 5 of 5

Thread: Solved: Treeview

  1. #1
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location

    Solved: Treeview

    I currently have the below code, however, it does not work the way that I wanted. The code will expand all of nodes with a click of a button. The problem is that after the nodes get expanded, I would like to retain my current position. I am not having luck.

    below code does not work, can someone give me a pointer as to how I may select back to where my position was before the expand button was clicked?


    [vba]
    Private Sub butExpandAll_Click()
    Dim xNode As Node
    Dim CurrentNode As Node

    Set CurrentNode = Me.TreeView1.SelectedItem
    For Each xNode In Me.TreeView1.Nodes
    xNode.Expanded = True
    Next xNode

    CurrentNode.EnsureVisible
    End Sub
    [/vba]

    Let me add more comment.... it sort of works, after staring at it for awhile, the once selected node is at the bottom of my tree control, and it is not selected anymore. So, is there a way to move it to the top and selected what was selected?

    Thanks
    Last edited by JKwan; 05-05-2011 at 02:38 PM.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    IF you include a simple sample file, it is easier to help.

  3. #3
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Quote Originally Posted by Kenneth Hobs
    IF you include a simple sample file, it is easier to help.
    I really didn't think people would it, given the nature.... here is my reduced version.
    Click on column Q, a form will pop up, the UWI will be hi-lighted, now, if you click the expand all button, the tree gets expanded, however, where the UWI was hi-lighted is now lost in the mess. How can I hi-light the UWI that was selected and move it to the top, rather than the bottom of the tree?
    Attached Files Attached Files

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I set your Sheet8 name to be the IWMS and removed that Set Range in the Open event code.

    Maybe:
    [vba]Private Sub butExpandAll_Click()
    Dim xNode As Node
    Dim currentnode As Node

    Set currentnode = Me.TreeView1.SelectedItem
    Me.TreeView1.Visible = False
    For Each xNode In Me.TreeView1.Nodes
    xNode.Expanded = True
    Next xNode

    ' Set Me.TreeView1.SelectedItem = CurrentNode
    Me.TreeView1.Visible = True
    'currentnode.EnsureVisible

    Set xNode = TreeViewFindNode(Me.TreeView1, SurfaceLocation)
    If Not xNode Is Nothing Then
    xNode.Checked = True
    xNode.Selected = True
    xNode.Expanded = True
    xNode.EnsureVisible
    End If
    Me.TreeView1.SetFocus
    End Sub
    [/vba]

  5. #5
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Thanks Kenneth, I don't know how I missed .Checked??

Posting Permissions

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