mctree Node Expander
-
- NewLounger
- Posts: 12
- Joined: 19 Feb 2014, 01:45
mctree Node Expander
Could you please help me to understand the VBA Code to set the Expander icon to plus / minus for a specific node on the (mctree) treeview control? Thank you.
P.S. BTW: Kudos to Peter for the most excellent work on his Treeview.
P.S. BTW: Kudos to Peter for the most excellent work on his Treeview.
-
- Administrator
- Posts: 78647
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: mctree Node Expander
Welcome to Eileen's Lounge!
I assume that you mean the All-VBA TreeView control created by Jan Karel Pieterse with the help of Peter Thornton, available from An MSForms (all VBA) treeview.
What exactly do you want to accomplish?
I assume that you mean the All-VBA TreeView control created by Jan Karel Pieterse with the help of Peter Thornton, available from An MSForms (all VBA) treeview.
What exactly do you want to accomplish?
Best wishes,
Hans
Hans
-
- Microsoft MVP
- Posts: 656
- Joined: 24 Jan 2010, 17:51
- Status: Microsoft MVP
- Location: Weert, The Netherlands
Re: mctree Node Expander
The state of the icon (whether present, whether plus or minus) is automatically chosen depending on whether or not the node in question has child nodes and whether or not it is expanded.
-
- NewLounger
- Posts: 12
- Joined: 19 Feb 2014, 01:45
Re: mctree Node Expander
I set up the treeview to open to a default view as follows:
Cable One (Root)
View Data
-Select Report
-Choose Month
Export Data
-Choose Month
Import Data
-Select Report
-Choose Month
When I click a level one node (View Data, Import Data and Export Data) I am unable to capture the click event because those nodes are already opened. I want the child nodes to open/close when the level one node is clicked. A click of a level one node should open/close the the child nodes (Select Report / Choose Month) at the same time. Therefore I was trying to set the Expander Icon to Win7Minus as the form loads. Otherwise, the value for the "Expanded" property is always set to True. I figured that changing the "Expander" icon to minus when the tree is loading would make for less coding. I appreciate your help and suggestions. Thank you.
Cable One (Root)
View Data
-Select Report
-Choose Month
Export Data
-Choose Month
Import Data
-Select Report
-Choose Month
When I click a level one node (View Data, Import Data and Export Data) I am unable to capture the click event because those nodes are already opened. I want the child nodes to open/close when the level one node is clicked. A click of a level one node should open/close the the child nodes (Select Report / Choose Month) at the same time. Therefore I was trying to set the Expander Icon to Win7Minus as the form loads. Otherwise, the value for the "Expanded" property is always set to True. I figured that changing the "Expander" icon to minus when the tree is loading would make for less coding. I appreciate your help and suggestions. Thank you.
-
- NewLounger
- Posts: 12
- Joined: 19 Feb 2014, 01:45
Re: mctree Node Expander
Following is how I solved the problem:
With Me.mcTree
cChild.Expanded = .Tag
.Tag = False
End With
But I thought perhaps there was similar code for changing the expander
like this code or similar that I found for the treeview common control:
TreeView1.SelectedItem.Child.selected = True
imageIndex = TreeView1.SelectedItem.Child.Key
TreeView1.SelectedItem.Child.Image = imageIndex
or kind of something simple like this with the outstanding TreeView control created by Jan Karel Pieterse with the help of Peter:
cNode.Image=iif(cNode.Level=1,"Win7Plus1","Win7Minus")
-David
With Me.mcTree
cChild.Expanded = .Tag
.Tag = False
End With
But I thought perhaps there was similar code for changing the expander
like this code or similar that I found for the treeview common control:
TreeView1.SelectedItem.Child.selected = True
imageIndex = TreeView1.SelectedItem.Child.Key
TreeView1.SelectedItem.Child.Image = imageIndex
or kind of something simple like this with the outstanding TreeView control created by Jan Karel Pieterse with the help of Peter:
cNode.Image=iif(cNode.Level=1,"Win7Plus1","Win7Minus")
-David
-
- Administrator
- Posts: 78647
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: mctree Node Expander
I'm not sure I understand what you're doing. To display the root only:
To display only the root and the nodes immediately below it:
etc.
This code should be called in the code module of the userform, after the treeview has been populated.
Code: Select all
mcTree.ExpandToLevel 0
mcTree.Refresh
Code: Select all
mcTree.ExpandToLevel 1
mcTree.Refresh
This code should be called in the code module of the userform, after the treeview has been populated.
Best wishes,
Hans
Hans
-
- NewLounger
- Posts: 12
- Joined: 19 Feb 2014, 01:45
Re: mctree Node Expander
Cool. Thanks Harris! I'll give it a try. -David
-
- NewLounger
- Posts: 12
- Joined: 19 Feb 2014, 01:45
Re: mctree Node Expander
Hi Harris, Could you please show me how to expand / collapse the third parent node along with its two child nodes using ScrollToView and/or ExpandtoLevel? Thank you. -David
-
- Administrator
- Posts: 78647
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: mctree Node Expander
Jan Karel may have to look into this. When I tried to call ExpandNode, Excel crashed. I think the code should be
but perhaps I'm way off.
In the attached demo, I used the following to expand the 3rd node below the root:
PS My name is Hans, not Harris...
Code: Select all
Public Sub ExpandNode(cNode As clsNode)
Dim cTmp As clsNode
Set cTmp = cNode.ParentNode
Do While Not cTmp.Caption = "RootHolder"
cTmp.Expanded = True
Set cTmp = cTmp.ParentNode
Loop
End Sub
In the attached demo, I used the following to expand the 3rd node below the root:
Code: Select all
mcTree.ExpandToLevel 1
mcTree.ExpandNode mcTree.Nodes("Root_3.1")
mcTree.Refresh
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- Microsoft MVP
- Posts: 656
- Joined: 24 Jan 2010, 17:51
- Status: Microsoft MVP
- Location: Weert, The Netherlands
Re: mctree Node Expander
I'm still not clear what you're trying to do. The expanding of nodes is already handled by the class, you whouldn't need to write any code to do that.
-
- NewLounger
- Posts: 12
- Joined: 19 Feb 2014, 01:45
Re: mctree Node Expander
Hi Jan, I'm trying to open the treeview with the default view shown below. Therefore, when a Level 1 Node is selected the child nodes should also open--and all other nodes should revert to the default view. Open a second Level 1 Node and the first Level 1 node i previously opened along with any open child nodes get closed. This seems like a simple idea and I keep hacking away to find the answer. Thank you your help. BTW: Your Treeview Control is undoubtedly one of the best learning tools for understanding VB/VBA and Class Modules. -David
Client Name (Root)
View Data (Level 1)
-Select Report (Level 2)
-Choose Month (Level 2)
Export Data (Level 1)
-Choose Month (Level 2)
Import Data (Level 1)
-Select Report (Level 2)
-Choose Month (Level 2)
Client Name (Root)
View Data (Level 1)
-Select Report (Level 2)
-Choose Month (Level 2)
Export Data (Level 1)
-Choose Month (Level 2)
Import Data (Level 1)
-Select Report (Level 2)
-Choose Month (Level 2)
-
- Microsoft MVP
- Posts: 656
- Joined: 24 Jan 2010, 17:51
- Status: Microsoft MVP
- Location: Weert, The Netherlands
Re: mctree Node Expander
I added this to the mcTree_Click event in the userform's code module:
Code: Select all
Dim cOtherNode As clsNode
For Each cOtherNode In mcTree.Nodes
If Not cNode Is cOtherNode And cOtherNode.ParentNode Is cNode.ParentNode Then
cOtherNode.Expanded = False
End If
Next
mcTree.Refresh
-
- Microsoft MVP
- Posts: 656
- Joined: 24 Jan 2010, 17:51
- Status: Microsoft MVP
- Location: Weert, The Netherlands
Re: mctree Node Expander
I forgot to include:
cNode.Expanded = True
just before the For-next loop...
cNode.Expanded = True
just before the For-next loop...
-
- NewLounger
- Posts: 12
- Joined: 19 Feb 2014, 01:45
Re: mctree Node Expander
I'll give it a try! Thank you, Jan!