1 Attachment(s)
[RESOLVED] Checkbox not work properly when clicked on quickly multiple times
I have done some code for checking treeview node
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
what this code do:
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
Attachment 176117
Is there a reason for this?
Please let me know if I missed anything.
Re: Checkbox not work properly when clicked on quickly multiple times
try it this way
Code:
Private Sub TreeView1_AfterCheck(sender As Object, e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
With e.Node
For Each nd As TreeNode In .Nodes
nd.Checked = .Checked
Next
End With
End Sub
hth
Re: Checkbox not work properly when clicked on quickly multiple times
This problem has been solved.
Please visit:
this link