treeview respond to single click [resolved]
I am working on a Windows Form application with a Treeview control. I would like the single click to fire up the Double click event. I am trying to respond to a single click on the Parent node description by expanding/collapsing the node. I would handle this in the AfterSelect event, but it is not fired if you single click an already selected node. How would I go about accomplishing this?
treeview respond to single click [resolved]
Finally got it to work. (Pirate: the beforeselect event does not respond to clicking an already active parent, which is why it was necessary to use the MouseDown event)
Private Sub tvwMenu_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwMenu.AfterSelect
Dim strKey As String
If (Not e.Node.Parent Is Nothing) Then
strKey = e.Node.Parent.Index & e.Node.Index
Else
strKey = e.Node.Index
End If
Select Case strKey
Case "00"
...
Case "01"
...
End Select
End Sub
Private Sub tvwMenu_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvwMenu.MouseDown
m_Status = "New"
Dim node As TreeNode
node = tvwMenu.GetNodeAt(e.X, e.Y)
If Not (node Is Nothing) And (node.Parent Is Nothing) Then
If node.IsExpanded Then
tvwMenu.GetNodeAt(e.X, e.Y).Collapse()
m_Status = "Done"
Else : tvwMenu.GetNodeAt(e.X, e.Y).Expand()
m_Status = "Done"
End If
End If
End Sub
Private Sub tvwMenu_BeforeCollapse(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles tvwMenu.BeforeCollapse
If m_Status = "Done" Then
e.Cancel = True
End If
End Sub
Private Sub tvwMenu_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles tvwMenu.BeforeExpand
If m_Status = "Done" Then
e.Cancel = True
End If
End Sub