Treeview Drag & Drop 
Author Message
 Treeview Drag & Drop

Hi!

I have used the samplecode from VB Books Online that shows how to drag
& Drop nodes in a TreeView control, but there seems to be a problem:

The node to be dragged must first be selected by clicking it, before
it can be dragged. The TreeView.SelectedItem seems to be updated after
alle Mouse events have been fired, which means, that the previously
selected node is the one, which will be dragged, if you don't remember
to click the new node before dragging it.

Is this a bug, and if so, is there a workaround for it? Or am I just
doing something wrong?

/Erik



Sun, 11 Mar 2001 03:00:00 GMT  
 Treeview Drag & Drop
        Who knows if it is a bug, or just another "feature."  What
works is something like this:

        private sub treecontrol_mousedown(button, x, y)  
                dim nd as node

                set nd = treecontrol.GetHit(x,y)
                if not nd is nothing then
                        nd.selected = true
                endif
        end sub

  OK, so I can't remember if it is GetHit or not, but there is a
method to tell you which node was clicked on with a specific X,Y
coord. Then just set that node to selected and your problem is fixed.

Jim Karczewski
Application Developer
UBS-Brinson



Quote:
>Hi!

>I have used the samplecode from VB Books Online that shows how to drag
>& Drop nodes in a TreeView control, but there seems to be a problem:

>The node to be dragged must first be selected by clicking it, before
>it can be dragged. The TreeView.SelectedItem seems to be updated after
>alle Mouse events have been fired, which means, that the previously
>selected node is the one, which will be dragged, if you don't remember
>to click the new node before dragging it.

>Is this a bug, and if so, is there a workaround for it? Or am I just
>doing something wrong?

>/Erik



Thu, 15 Mar 2001 03:00:00 GMT  
 Treeview Drag & Drop
The correct procedure name is HitTest

And - in order to move the selection - you need to do:

  set treecontrol.selecteditem = nothing
  set treecontrol.drophighlight = nothing

  set treecontrol.selecteditem = nd
  set treecontrol.drophighlight = nd

Regards
Ole

Quote:

> Who knows if it is a bug, or just another "feature."  What
>works is something like this:

> private sub treecontrol_mousedown(button, x, y)
> dim nd as node

> set nd = treecontrol.GetHit(x,y)
> if not nd is nothing then
> nd.selected = true
> endif
> end sub

>  OK, so I can't remember if it is GetHit or not, but there is a
>method to tell you which node was clicked on with a specific X,Y
>coord. Then just set that node to selected and your problem is fixed.

>Jim Karczewski
>Application Developer
>UBS-Brinson




Fri, 16 Mar 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. TreeView Drag & Drop

2. Treeview - Drag & Drop

3. TreeView, drag & drop, and OLEStartDrag

4. TreeView, Drag & Drop

5. Drag & Drop with TreeView control

6. ole drag&drop of file from an activex/ treeview headache

7. TreeView + ListView +Drag&Drop

8. Drag&Drop from NT Explorer to the treeview control

9. Drag&Drop in treeview

10. TreeView with Drag & Drop

11. Drag&Drop in Treeview with HitTest and DropHighlight

12. Drag & Drop in TreeView

 

 
Powered by phpBB® Forum Software