Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TreeView - check all children 3

Status
Not open for further replies.

pokermat

Programmer
Jan 17, 2002
44
GB
Hi

I am using a TreeView with checkboxes. When the user checks a checkbox at any level - I want all the child nodes of the selected node to be checked in code.

Anyone done this?

Many thanks.
 
Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
Dim CNode As Node

For Each CNode In TreeView1.Nodes
If CNode.Parent Is Node Then CNode.Checked = CNode.Parent.Checked
Next CNode

End Sub


Robert
 
Note that this will only check/uncheck the boxes of children on the first child level of the box you checked/unchecked. If you want to drill down all levels, then it's different.

Robert
 
Here. Use this if you need all "children of the children" to check and uncheck. This uses a function so it can recursively call itself and drill down through all levels..

Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)

NodeCHK Node

End Sub

Public Function NodeCHK(ByVal Node As MSComctlLib.Node)
Dim CNode As MSComctlLib.Node

For Each CNode In TreeView1.Nodes
If CNode.Parent Is Node Then
CNode.Checked = CNode.Parent.Checked
If CNode.Children > 0 Then NodeCHK CNode
End If
Next CNode

End Function


Robert
 
Thanks very much Robert - exactly what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top