Windows Develop Bookmark and Share   
 index > Windows Forms General > How to check all ChildItems in a TreeView??
 

How to check all ChildItems in a TreeView??

Hi!

I have a CheckedTreeView with an event "AfterCheck". So, always, when the Check-State of a button changes, the event is fired. In the event, I want to check or uncheck all child-Items of the selected Item.

So, I wrote a recursive method, that should work just fine. But the problem is, that I use the command "node.Checked = true" to check the childNodes. And always when the command is executed, the "AfterCheck"-event is executed.

Is there a way to suppress this event?

Or is there an easier way to check or uncheck all childItems in a treeView?

Thanks,
Barthi
Barthi  Friday, July 07, 2006 2:27 PM
Try this:

Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
Static itsMe As Boolean
If Not itsMe Then
itsMe = True
recurseNodes(e.Node, e.Node.Checked)
itsMe = False
End If
End Sub
Private Sub recurseNodes(ByVal nd As TreeNode, ByVal chk As Boolean)
For Each child As TreeNode In nd.Nodes
child.Checked = chk
recurseNodes(child, chk)
Next
End Sub

nobugz  Friday, July 07, 2006 3:22 PM
Try this:

Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
Static itsMe As Boolean
If Not itsMe Then
itsMe = True
recurseNodes(e.Node, e.Node.Checked)
itsMe = False
End If
End Sub
Private Sub recurseNodes(ByVal nd As TreeNode, ByVal chk As Boolean)
For Each child As TreeNode In nd.Nodes
child.Checked = chk
recurseNodes(child, chk)
Next
End Sub

nobugz  Friday, July 07, 2006 3:22 PM

You can use google to search for other answers

Custom Search

More Threads

• MDI Container layout
• Forms Ressources
• MessageBox custom button text
• adding an event handler to a checkbox in a datagrid
• TypeDescriptionProvider attribute is ignored with generic Form
• WebBrowser's Navigate method crashes
• Save a web form as mht or html
• Pixel colors found using GDI+ are different!!!!!
• Tooltip disappears intermittently
• Hide / unhide part of the main form