|
-
May 30th, 2004, 02:07 AM
#1
Thread Starter
Junior Member
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?
Last edited by ingineu; Jun 5th, 2004 at 11:35 AM.
-
May 31st, 2004, 11:27 AM
#2
Hyperactive Member
Yes I noticed the same frustrating behaviour, if you change the node and then reselect it works fine. For the moment I've put in the I'll get around to it one day list.
As a suggestion maybe the gotfocus event gets fired and you can check it's state and perhaps expand or collpase as you need. I don't know that is a solutuoin, just something to try.
-
May 31st, 2004, 12:13 PM
#3
Sleep mode
I found a solution that worked great for me . It's like this : \
in the TreeView BeforeSelect event , the code goes like this :
PHP Code:
if (e.Node.Parent==null)
{
switch (e.Node.Index)
{
case (0); //this is the first parent node
//do this
case (1);// second parent node .
//do this
}
}
This way , child node events won't fire .
-
Jun 1st, 2004, 01:53 PM
#4
Thread Starter
Junior Member
The BeforeSelect event does not fire if you click on an already selected Parent. Is there a way to, in the treeview Click event, fire the treeview DoubleClick event from code? I'm relatively new to VB.Net. I am converting from Access 2002, where the treeview control did exactly what I was after.
-
Jun 4th, 2004, 10:35 AM
#5
Thread Starter
Junior Member
In the MouseDown event, is there a way I can tell whether the Treeview Label was clicked as opposed to the +/- box?
-
Jun 4th, 2004, 07:27 PM
#6
Sleep mode
This always works fine with me . You can make use of param named "TreeViewCancelEventArgs". It gives you some info about everything on the node that's in action .
VB Code:
Private Sub TreeView1_BeforeSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeSelect
If e.Node.Parent Is Nothing Then
If e.Action.ByMouse = TreeViewAction.ByMouse AndAlso e.Action.Collapse = TreeViewAction.Collapse Then
MsgBox("You pressed Parent node")
End If
End If
End Sub
-
Jun 5th, 2004, 11:30 AM
#7
Thread Starter
Junior Member
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
Last edited by ingineu; Jun 5th, 2004 at 11:37 AM.
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
|