1

I have a treeview with parent and child nodes. all of them have check boxes. I did the code of checking/unchecking all the childs when the parent is checked/unchecked.

I have a problem when mouse double click on tree view parent check box, sometimes all the childs get checked some times all of them not checked. thee treeview after check code is working fine , but my problem is with mouse double click , so i need to paste the tree_after check code and trigger it from inside the mouse double click too.

     Private Sub node_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterCheck
            ' The code only executes if the user caused the checked state to change.
            If e.Action <> TreeViewAction.Unknown Then
                If e.Node.Nodes.Count > 0 Then
                    ' Calls the CheckAllChildNodes method, passing in the current 
                    ' Checked value of the TreeNode whose checked state changed. 
                    Me.CheckAllChildNodes(e.Node, e.Node.Checked)
                End If
            End If
        End Sub


 Private Sub TreeView1_MouseClick(sender As Object, e As MouseEventArgs) Handles TreeView1.MouseClick
'how i trigger the node_AfterCheck from here

    End Sub

    Private Sub TreeView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles TreeView1.MouseDoubleClick

'how i trigger the node_AfterCheck from here
    End Sub
Nadir
  • 55
  • 6
  • 2
    https://stackoverflow.com/questions/3174412/winforms-treeview-recursively-check-child-nodes-problem – Hans Passant Apr 15 '22 at 12:34
  • Thansk Hans, I am trying to use it , mean while is there a chance you show me how to do it using my above question ? I need to trigger the same code from different places , Thanks Hans – Nadir Apr 15 '22 at 13:56
  • 2
    If you need to execute the same code on multiple events then you should put the code in its own method and then call that from multiple event handlers. Assuming that the `e` parameter is compatible, you can use a single method to handle multiple events in the first place, but that is unlikely to be possible in situations where you actually need to use `e`. – user18387401 Apr 15 '22 at 15:43
  • 1
    https://stackoverflow.com/a/61307707/14171304 - I'd add to that the tri-state style. `TVS_EX_PARTIALCHECKBOXES = &H80`. – dr.null Apr 16 '22 at 00:19
  • 1
    Thank You dr.null, Hans and –user18387401 . dr.null, the link you gave worked wonderfully :) Thank you – Nadir Apr 16 '22 at 09:52

0 Answers0