Treeview Checkboxes

J

jamesdorringtonuk

Hi, I have a checkbox treeview control in a form, but currently, if
you check a root node (or any node for that matter) it does not
automatically check the sub-nodes. Is there a setting on the control
that I need to use to make this behaviour default or do I need to
manually check all subnodes myself, perhaps on the AfterCheck event?

Many TIA
 
H

Herfried K. Wagner [MVP]

Hi, I have a checkbox treeview control in a form, but currently, if
you check a root node (or any node for that matter) it does not
automatically check the sub-nodes. Is there a setting on the control
that I need to use to make this behaviour default or do I need to
manually check all subnodes myself, perhaps on the AfterCheck event?

Untested:

\\\
Private Sub TreeView1_AfterCheck( _
ByVal sender As Object, _
ByVal e As TreeViewEventArgs _
) Handles TreeView1.AfterCheck
e.Node.CheckSubNodes(e.Node.Checked)
End Sub
....
Public Module TreeeViewExtensions
<Extension()> _
Public Sub CheckSubNodes( _
ByVal Node As TreeNode, ByVal Checked As Boolean _
)
For Each SubNode As TreeNode In Node.Nodes
SubNode.Checked = Checked
CheckSubNodes(SubNode, Checked)
Next SubNode
End Sub
End Module
///
 
H

Herfried K. Wagner [MVP]

Hi, I have a checkbox treeview control in a form, but currently, if
you check a root node (or any node for that matter) it does not
automatically check the sub-nodes. Is there a setting on the control
that I need to use to make this behaviour default or do I need to
manually check all subnodes myself, perhaps on the AfterCheck event?

Untested:

\\\
Private Sub TreeView1_AfterCheck( _
ByVal sender As Object, _
ByVal e As TreeViewEventArgs _
) Handles TreeView1.AfterCheck
e.Node.CheckSubNodes(e.Node.Checked)
End Sub
....
Public Module TreeeViewExtensions
<Extension()> _
Public Sub CheckSubNodes( _
ByVal Node As TreeNode, ByVal Checked As Boolean _
)
For Each SubNode As TreeNode In Node.Nodes
SubNode.Checked = Checked
CheckSubNodes(SubNode, Checked)
Next SubNode
End Sub
End Module
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top