Untested code. To modify the parents, use the Parent property.
Dim parent as TreeNode = node.Parent
Do While parent IsNot Nothing Then
parent.Checked = False
parent = parent.Parent
Loop
To go the other way, you need to recurse through all of the children:
CheckChildren(n ode)
Private Sub CheckChildren(n ode As TreeNode)
Dim child as TreeNode = node.FirstNode
Do While child IsNot Nothing Then
child.Checked = True
CheckChildren(c hild)
child = child.NextNode
Loop
End Sub
While that does what you asked, I'm not sure it is what you really
want. If you check a node, all of the children get set. But if you
uncheck one of those children, only the child's parents, grandparents,
etc. will be unchecked, not the child's siblings.
On Fri, 29 Feb 2008 12:55:01 -0800, mabond
<ma****@discuss ions.microsoft. comwrote:
>I'm using a treeview control.
One parent node, several child nodes, several grandchild nodes.
Each of the nodes has a checkbox.
My question, when the user changes the check value of one of the grandchild
nodes to true how do I automatically change that node's parent to check-true
and so on up the tree.....and in reverse if the parent is changed to
check-false how do I cascade that down to each of the child nodes and their
child nodes.
Any help appreciated
Michael Bond