how to disable events in treeview

  • 12 years ago
    hello, I want to disable de double click event in treeview.

    The reason is that I don't want that when you do double click over a node, automatically unfolds a child node, and I don't want this.

    how I can do that when I do double click in a node, don't occurs anything?

  • 12 years ago

    I'm not entirely sure what you could do with this but there is a doubleclick event for the treeview control

       Private Sub TreeView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.DoubClick

       End Sub

    Maybe there is a way not to do anything with the childnode from this?



  • 12 years ago

    That's the way the TreeView is supposed to work.  I'd say that you would have to create your own class that inherits from the TreeView class and override the current double-click behaviour.

  • 12 years ago

    I think that the behaviour when I do double click in a node, doesn't is a event, I think that is a property of the treeview, but I don't find this property.

    I think this because if add code in the double click event, when I do double click in a node, a childnode is expanded and the code of the event is executed.


  • 12 years ago

    ' No Double-Click

    Protected bDoubleClick as boolean

    Private Sub treStructure_BeforeExpand(ByVal sender As   System.Object, ByVal e As       System.Windows.Forms.TreeViewCancelEventArgs) Handles treStructure.BeforeExpand

      If bDoubleClick Then
        bDoubleClick = False
        e.Cancel = True
      End If

    End Sub

    Private Sub treStructure_MouseDown(ByVal sender As System.Object, ByVal e As             System.Windows.Forms.MouseEventArgs) Handles treStructure.MouseDown
      Dim xNode As TreeNode

      If e.Button = MouseButtons.Left Then
        xNode = treStructure.GetNodeAt(e.X, e.Y)
        If Not xNode Is Nothing Then
          If Not xNode.IsExpanded And xNode.GetNodeCount(False) > 0 Then
            If e.Clicks = 2 Then
              bDoubleClick = True
            End If
          End If
        End If
      End If

    End Sub

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An expert is a man who has made all the mistakes that can be made in a very narrow field” - Niels Bohr