Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2021
  • Last Modified:

Check/Decheck nodes in TreeView VBA Excel

Hi,
How can I Check/Decheck all nodes in treeView depending of selected node...
For example...
Root
       Parent1
                   Parent2
                               Child1
                               Child2
                               Child3

If I check Parent1 I would like to check also all below (Parent2, Child1,Child2,Child3)...
Also, the same should be applied as for deselect....
I would appreciate help a lot
Regards
0
alsam
Asked:
alsam
1 Solution
 
Rory ArchibaldCommented:
For example, assuming a Treeview called tvwMain:
Private Sub tvwMain_NodeCheck(ByVal Node As MSComctlLib.Node)
      CheckNodes Node, Node.Checked
End Sub
Private Sub CheckNodes(ByRef oParentNode As Node, ByVal bChecked As Boolean)
 Dim oNode As Node
 ' Get the first child node
 Set oNode = oParentNode.Child
 ' Loop through the child nodes of this node
 ' until there are none left...
 Do While Not oNode Is Nothing
   ' Check/Uncheck the node
   oNode.Checked = bChecked
   ' Call this function again for the
   ' child node, so that its child nodes
   ' can get checked/unchecked.
   CheckNodes oNode, bChecked
   ' Get the next child node of this node
   Set oNode = oNode.Next
 Loop
End Sub

Open in new window


HTH
Rory
0
 
alsamAuthor Commented:
Helped me a lot...

Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now