Posted By

PUN1SH3R on 05/07/08


Tagged

view tree TreeView checked nodes


Versions (?)

Check Parent Node When Last Child is Checked


 / Published in: VB.NET
 

This code allows you to check the parent node in a TreeView control when the last child node is checked.

  1. Private Sub TreeView1_AfterCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
  2.  
  3. Dim blnUncheck As Boolean = False
  4.  
  5. 'Check to see if a parent node exists.
  6. If Not e.Node.Parent Is Nothing Then
  7.  
  8. 'Loop through the child nodes.
  9. For Each child As TreeNode In e.Node.Parent.Nodes
  10.  
  11. 'Check to see if the current node is unchecked.
  12. If child.Checked = False Then
  13.  
  14. 'Set the variable.
  15. blnUncheck = True
  16. End If
  17. Next
  18.  
  19. 'Check the variable.
  20. If blnUncheck = False Then
  21.  
  22. 'Check the parent node.
  23. e.Node.Parent.Checked = True
  24. Else
  25.  
  26. 'Uncheck the parent node.
  27. e.Node.Parent.Checked = False
  28. End If
  29.  
  30. End If
  31.  
  32. End Sub

Report this snippet  

You need to login to post a comment.