Expand a Treeview node during drag operation 
Author Message
 Expand a Treeview node during drag operation

I want to automatically expand a treeview node when the cursor moves over a collapsed node. An example of this kind of
behaviour can be seen when performing drag and drop operations in Windows Explorer. Explorer will expand folders so that
you can drop your files on the sub-folders.

When I use the .HitTest method or the DropHighlight property, I get run-time error '91': "Object variable or With block
variable not set". Below is a sample of the code that I'm using. Is there a way to get this code to run with using an
"On Error Resume Next" statement on the line that fails?

Private Sub tv1_DragOver _
   (Source As Control, _
   x As Single, _
   y As Single, _
   State As Integer)

   If indrag = True Then
      ' Set DropHighlight to the mouse's coordinates.
      Set tv1.DropHighlight = tv1.HitTest(x, y)
      tv1.Nodes(tv1.DropHighlight.Index).Expanded = True    ' fails here :-(
   End If
End Sub



Fri, 28 Mar 2003 03:00:00 GMT  
 Expand a Treeview node during drag operation

You need to check if the HitTest function returned a valid Node or not:

Set tv1.DropHighlight = tv1.HitTest(x, y)

If Not tv1.DropHighlight Is Nothing Then
    tv1.Nodes(tv1.DropHighlight.Index).Expanded = True    ' works here ;-)
End If

Good Luck,

Joe


Quote:
> I want to automatically expand a treeview node when the cursor moves over

a collapsed node. An example of this kind of
Quote:
> behaviour can be seen when performing drag and drop operations in Windows

Explorer. Explorer will expand folders so that
Quote:
> you can drop your files on the sub-folders.

> When I use the .HitTest method or the DropHighlight property, I get

run-time error '91': "Object variable or With block
Quote:
> variable not set". Below is a sample of the code that I'm using. Is there

a way to get this code to run with using an
Quote:
> "On Error Resume Next" statement on the line that fails?

> Private Sub tv1_DragOver _
>    (Source As Control, _
>    x As Single, _
>    y As Single, _
>    State As Integer)

>    If indrag = True Then
>       ' Set DropHighlight to the mouse's coordinates.
>       Set tv1.DropHighlight = tv1.HitTest(x, y)
>       tv1.Nodes(tv1.DropHighlight.Index).Expanded = True    ' fails here
:-(
>    End If
> End Sub



Sat, 29 Mar 2003 03:00:00 GMT  
 Expand a Treeview node during drag operation
Thank you.
Kent
Quote:

> You need to check if the HitTest function returned a valid Node or not:

> Set tv1.DropHighlight = tv1.HitTest(x, y)

> If Not tv1.DropHighlight Is Nothing Then
>     tv1.Nodes(tv1.DropHighlight.Index).Expanded = True    ' works here ;-)
> End If

> Good Luck,

> Joe



> > I want to automatically expand a treeview node when the cursor moves over
> a collapsed node. An example of this kind of
> > behaviour can be seen when performing drag and drop operations in Windows
> Explorer. Explorer will expand folders so that
> > you can drop your files on the sub-folders.

> > When I use the .HitTest method or the DropHighlight property, I get
> run-time error '91': "Object variable or With block
> > variable not set". Below is a sample of the code that I'm using. Is there
> a way to get this code to run with using an
> > "On Error Resume Next" statement on the line that fails?

> > Private Sub tv1_DragOver _
> >    (Source As Control, _
> >    x As Single, _
> >    y As Single, _
> >    State As Integer)

> >    If indrag = True Then
> >       ' Set DropHighlight to the mouse's coordinates.
> >       Set tv1.DropHighlight = tv1.HitTest(x, y)
> >       tv1.Nodes(tv1.DropHighlight.Index).Expanded = True    ' fails here
> :-(
> >    End If
> > End Sub



Sat, 29 Mar 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Get the Node for the Drag/Drop Operation in the Treeview

2. Expanding Treeview to show selected node

3. Expanding node of treeview

4. TreeView not expanding by DblClick on a node

5. Treeview last node allway expanded

6. TreeView node expand/collapse

7. TreeView - defeating double-click node collapse/expand

8. expand a selected treeview node ?

9. Expand TreeView Node programtically

10. Treeview - Expand a Node Programatically

11. Change the OLE DragDrop Icon during OLE Drag Drop operation

12. TreeView: flicker during adding new nodes

 

 
Powered by phpBB® Forum Software