PDA

View Full Version : Solved: Treeview



JKwan
05-05-2011, 02:13 PM
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?



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


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

Kenneth Hobs
05-05-2011, 05:45 PM
IF you include a simple sample file, it is easier to help.

JKwan
05-06-2011, 06:01 AM
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?

Kenneth Hobs
05-06-2011, 06:26 PM
I set your Sheet8 name to be the IWMS and removed that Set Range in the Open event code.

Maybe:
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

JKwan
05-07-2011, 07:24 AM
Thanks Kenneth, I don't know how I missed .Checked??