Drag and Drop in Treeview control

emady

Board Regular
Joined
Feb 19, 2003
Messages
228
Hi everyone,

I have an access form that has a treeview activeX control in it.
I want to be able to drag a node from one position to another within the same treeview control. I know the index of the node being dragged using the ClickNode event but :oops: the problem I am facing is that I can't find a way to know where the dragged item is being dropped. All I get from OLEDragDrop event is x and y coordinates which I don't know how to relate to the nodes in the treeview control.

Can anyone help me please????

Thanks,

Elia
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi,

Look at the Hittest method of the treeview. It does exactly what you want :)
 
Upvote 0
I have one more question please:
How can you have the treeview control to autoexpand?

Thanks

Elia
 
Upvote 0
Hi,

You can control it using the Expanded property. This code should demonstrate it:-

Code:
Private Sub UserForm_Initialize()
PopulateTreeView
End Sub


Private Sub PopulateTreeView()
'Sample code for populating a treeview control on a VBA userform
'Daniel Klann, 12th Februrary 2004

    Dim tvwNode As Node

    With Me.TreeView1

        Set tvwNode = .Nodes.Add(Key:="Earth", Text:="Earth")

        'This line below will tell the treeview control that we want the children of Earth
        'to be expanded by default i.e. the countries will be visible when the form is first opened.
        tvwNode.Expanded = True

        'Add UK and UK towns
        .Nodes.Add relative:="Earth", relationship:=tvwChild, Key:="UK", Text:="UK"
        .Nodes.Add relative:="UK", relationship:=tvwChild, Key:="Woking", Text:="Woking"
        .Nodes.Add relative:="UK", relationship:=tvwChild, Key:="London", Text:="London"

        'Add USA and USA towns
        .Nodes.Add relative:="Earth", relationship:=tvwChild, Key:="USA", Text:="USA"
        .Nodes.Add relative:="USA", relationship:=tvwChild, Key:="New York", Text:="New York"
        .Nodes.Add relative:="USA", relationship:=tvwChild, Key:="San Diego", Text:="San Diego"

        'Add Australia and Australian towns
        .Nodes.Add relative:="Earth", relationship:=tvwChild, Key:="Australia", Text:="Australia"
        .Nodes.Add relative:="Australia", relationship:=tvwChild, Key:="Sydney", Text:="Sydney"
        .Nodes.Add relative:="Australia", relationship:=tvwChild, Key:="Cairns", Text:="Cairns"


    End With

End Sub
 
Upvote 0
Hi... Can you show an example of code processing the drag and drop events? I want to move items on my spreadsheet as they are moved in my treeview.

Thanks.
 
Upvote 0

Forum statistics

Threads
1,207,191
Messages
6,076,995
Members
446,248
Latest member
tim_crouse

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top