469,625 Members | 1,127 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Treeview check change

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
Feb 29 '08 #1
2 3044
On Fri, 29 Feb 2008 12:55:01 -0800, mabond
<ma****@discussions.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
Mar 1 '08 #2
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(node)

Private Sub CheckChildren(node As TreeNode)
Dim child as TreeNode = node.FirstNode

Do While child IsNot Nothing Then
child.Checked = True
CheckChildren(child)
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****@discussions.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
Mar 1 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

42 posts views Thread by lauren quantrell | last post: by
1 post views Thread by paradox | last post: by
1 post views Thread by Aleksey | last post: by
2 posts views Thread by Srinivasa Raghavan | last post: by
1 post views Thread by jyoti ranjan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.