VB Treeview event NodeMouseClick raised on node double click !!! How to avoid this.

  • Thread starter Thread starter Alex Cote
  • Start date Start date
A

Alex Cote

Guest
Hi,

I have a problem with the Treeview control, when I try to use the NodeMouseDoubleClick event the even NodeMouseClick is also fired just before ...

Anyone can explain me how to avoid the NodeMouseClick event to be raised on a node double click.

Here's a simple example to reproduce the behavior:

Imports System.IO
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim rootNode As New TreeNode
rootNode.Text = "C:\Temp"
TreeView1.Nodes.Add(rootNode)

Dim di As DirectoryInfo = New DirectoryInfo(rootNode.Text)
Dim flds() As DirectoryInfo = di.GetDirectories("*")
Dim rNode As TreeNode

If flds.Count <> 0 Then
For Each fldt As DirectoryInfo In flds
rNode = New TreeNode
rNode.Name = fldt.Name
rNode.Text = rNode.Name
TreeView1.TopNode.Nodes.Add(rNode)

Dim subDir() As DirectoryInfo = fldt.GetDirectories("*")
If subDir.Count > 0 Then
rNode.Nodes.Add("Dummy")
End If
Next
End If

Catch ex As Exception
MsgBox(ex.Message & vbNewLine & vbNewLine & ex.StackTrace)
End Try
End Sub

Private Sub TreeView1_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick
Debug.Print("Node Mouse Click - Number of click: " & e.Clicks)
End Sub

Private Sub TreeView1_NodeMouseDoubleClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick
Debug.Print("Node Mouse Double Click - Number of click: " & e.Clicks)
End Sub
Private Sub TreeView1_MouseClick(sender As Object, e As MouseEventArgs) Handles TreeView1.MouseClick
Debug.Print("Mouse Click - Number of click: " & e.Clicks)
End Sub
Private Sub TreeView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles TreeView1.MouseDoubleClick
Debug.Print("Mouse Double Click - Number of click: " & e.Clicks)
End Sub
End Class
Regards

Continue reading...
 
Back
Top