|
-
Apr 16th, 2020, 01:54 AM
#1
Thread Starter
New Member
[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

Is there a reason for this?
Please let me know if I missed anything.
-
Apr 16th, 2020, 02:50 AM
#2
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
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Apr 22nd, 2020, 04:46 AM
#3
Thread Starter
New Member
Re: Checkbox not work properly when clicked on quickly multiple times
This problem has been solved.
Please visit:
this link
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|