I have done some code for checking treeview node
what this code do:Code:Private Sub TreeView1_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterCheck If updatingTreeView Then Return updatingTreeView = True CheckNode(e.Node, e.Node.Checked) HasCheckedChildNode = 0 updatingTreeView = False End Sub Private Sub CheckNode(node As TreeNode, isChecked As Boolean) If node.Parent IsNot Nothing Then HasCheckedNode(node.Parent) If Not isChecked And HasCheckedChildNode > 0 Then Return node.Parent.Checked = isChecked ElseIf node.Parent Is Nothing Then For Each cn As TreeNode In node.Nodes cn.Checked = isChecked Next End If End Sub Private Sub HasCheckedNode(node As TreeNode) For Each cn As TreeNode In node.Nodes If cn.Checked = True Then HasCheckedChildNode += 1 ElseIf cn.Checked = False Then HasCheckedChildNode -= 0 End If Next End Sub
1. If parent node is checked/unchecked, also check/uncheck all child nodes
2. If just one child node is checked, also check parent node
3. If the last child node is unchecked, also uncheck parent node
this code works fine.
Problem:
When I clicks quickly some of the checkboxes are checked and some no
E.g. sometimes I checked the parent node but all child nodes still remain uncheck
Is there a reason for this?
Please let me know if I missed anything.




Reply With Quote
