Get TreeView MouseUp event to recognize parent/child 
Author Message
 Get TreeView MouseUp event to recognize parent/child

Private Sub TreeView1_MouseUp(Button As Integer, _
    Shift As Integer, x As Single, y As Single)

Dim oNode As MSComctlLib.Node

    If Button = vbRightButton Then
        Set oNode = TreeView1.HitTest(x, y)
        If Not oNode Is Nothing Then
            'Mouse is on a node (oNode)

            'If you want this to become the active node...
            Set TreeView1.SelectedItem = oNode

            'Test for parent node
            If oNode.Children > 0 Then
                'Node has children (parent node)
            Else
                'Node has no children (leaf node)
            End If
        Else
            'Mouse is not on any node
        End If
    End If

End Sub

HTH,
Rocky Clark (Kath-Rock Software)


Quote:
> Hi All:

> I have a treeview control that allows a popup menu to
> appear by using the MouseUp event of TreeView control.
> However, how do I test whether the user has right-clicked
> on a parent node, a child node, or just white space?

> tod



Sat, 10 Jul 2004 02:21:57 GMT  
 Get TreeView MouseUp event to recognize parent/child


Fri, 19 Jun 1992 00:00:00 GMT  
 Get TreeView MouseUp event to recognize parent/child
Perfect.

May you be blessed with many dracma. Long live jambi.

Quote:
>-----Original Message-----
>Private Sub TreeView1_MouseUp(Button As Integer, _
>    Shift As Integer, x As Single, y As Single)

>Dim oNode As MSComctlLib.Node

>    If Button = vbRightButton Then
>        Set oNode = TreeView1.HitTest(x, y)
>        If Not oNode Is Nothing Then
>            'Mouse is on a node (oNode)

>            'If you want this to become the active node...
>            Set TreeView1.SelectedItem = oNode

>            'Test for parent node
>            If oNode.Children > 0 Then
>                'Node has children (parent node)
>            Else
>                'Node has no children (leaf node)
>            End If
>        Else
>            'Mouse is not on any node
>        End If
>    End If

>End Sub

>HTH,
>Rocky Clark (Kath-Rock Software)



>> Hi All:

>> I have a treeview control that allows a popup menu to
>> appear by using the MouseUp event of TreeView control.
>> However, how do I test whether the user has right-
clicked
>> on a parent node, a child node, or just white space?

>> tod

>.



Sat, 10 Jul 2004 03:06:17 GMT  
 Get TreeView MouseUp event to recognize parent/child


Fri, 19 Jun 1992 00:00:00 GMT  
 Get TreeView MouseUp event to recognize parent/child
This works ideally, except for one thing. If I only have
one parent and it has no children, it beleives that the
node is a child. It's not likely that my tree will ever
have just one parent and no children, but I want to cover
for that.

Quote:
>-----Original Message-----
>Private Sub TreeView1_MouseUp(Button As Integer, _
>    Shift As Integer, x As Single, y As Single)

>Dim oNode As MSComctlLib.Node

>    If Button = vbRightButton Then
>        Set oNode = TreeView1.HitTest(x, y)
>        If Not oNode Is Nothing Then
>            'Mouse is on a node (oNode)

>            'If you want this to become the active node...
>            Set TreeView1.SelectedItem = oNode

>            'Test for parent node
>            If oNode.Children > 0 Then
>                'Node has children (parent node)
>            Else
>                'Node has no children (leaf node)
>            End If
>        Else
>            'Mouse is not on any node
>        End If
>    End If

>End Sub

>HTH,
>Rocky Clark (Kath-Rock Software)



>> Hi All:

>> I have a treeview control that allows a popup menu to
>> appear by using the MouseUp event of TreeView control.
>> However, how do I test whether the user has right-
clicked
>> on a parent node, a child node, or just white space?

>> tod

>.



Sat, 10 Jul 2004 03:54:42 GMT  
 Get TreeView MouseUp event to recognize parent/child

<snip>
            'Test for parent node
            If oNode.Children > 0 Then
                'Node has children (parent node)
            Else
                'Node has no children (possible child)
                If oNode.Parent Is Nothing Then
                    'It's a top level node
                Else
                    'It's a child node
                End If
            End If
<snip>

HTH,
Rocky


Quote:
> This works ideally, except for one thing. If I only have
> one parent and it has no children, it beleives that the
> node is a child. It's not likely that my tree will ever
> have just one parent and no children, but I want to cover
> for that.

> >-----Original Message-----
> >Private Sub TreeView1_MouseUp(Button As Integer, _
> >    Shift As Integer, x As Single, y As Single)

> >Dim oNode As MSComctlLib.Node

> >    If Button = vbRightButton Then
> >        Set oNode = TreeView1.HitTest(x, y)
> >        If Not oNode Is Nothing Then
> >            'Mouse is on a node (oNode)

> >            'If you want this to become the active node...
> >            Set TreeView1.SelectedItem = oNode

> >            'Test for parent node
> >            If oNode.Children > 0 Then
> >                'Node has children (parent node)
> >            Else
> >                'Node has no children (leaf node)
> >            End If
> >        Else
> >            'Mouse is not on any node
> >        End If
> >    End If

> >End Sub

> >HTH,
> >Rocky Clark (Kath-Rock Software)



> >> Hi All:

> >> I have a treeview control that allows a popup menu to
> >> appear by using the MouseUp event of TreeView control.
> >> However, how do I test whether the user has right-
> clicked
> >> on a parent node, a child node, or just white space?

> >> tod

> >.



Sat, 10 Jul 2004 19:53:43 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. TreeView MouseUp event not firing

2. TreeView : child with multiple parents

3. Select parent or children in treeview

4. TreeView Parent/Child Expanded Question

5. Move Treeview Child Node To Different Parent

6. treeview parent or child ?

7. TreeView Drag n Drop don't allow dropping a parent into a child

8. ReOrdering Child nodes Within Parent in treeview

9. Treeview/listview to display Parent-child recordsets

10. Passing MDI Parents menu click events to child forms

11. mdi parent/child unload events

12. Parent & Child Menu Click Events

 

 
Powered by phpBB® Forum Software