Avatar of beidebenen
Flag for Netherlands asked on

Drag and drop to a specified place i a field using MSComctlLib.TreeCtrl.2

I using a treeview to show some default text an like to use drag an drop to put the default text in a controlbox.

So far so good BUT

I like to drop the default text (for example) inside the text I have already placed in a textcontrol. Who can help me with this problem.
Microsoft Access

Avatar of undefined
Last Comment
Scott McDaniel (EE MVE )

8/22/2022 - Mon
Scott McDaniel (EE MVE )

Access doesn't do drag and drop. Your Treeview may support it, but that would only be between another control that also supported drag and drop.

There are some alternatives, but I'm not sure they would work with your Treeview:

www.peterssoftware.com (Drag and Dropper)

How to simulate Drag and Drop:


I change my design and using now a forms.TextBox.1 and the treeview control. It works but now the value I drag is moving from my treeview list.

Ok it is drag and drop but :)

I like to drop the value and leave the treeview list in order.  So I hope someone can tell me what I do wrong.

Private Sub TvScript_OLEDragOver(Data As Object, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)
    Dim nodSelected As Node
    Dim nodOver As Node
    Dim tv As TreeView
    Set tv = Me.TvScript.Object
    If tv.SelectedItem Is Nothing Then
        'Select a node if one is not selected
        Set nodSelected = tv.HitTest(x, y)
        If Not nodSelected Is Nothing Then
            nodSelected.Selected = True
        End If
        tv.SelectedItem.Selected = True
    End If
End Sub

Open in new window

Scott McDaniel (EE MVE )

I'm not sure what you mean by "leave the treeview list in order" ... all your code does is select a Node in your treeview, so I'm not clear what you're asking.
Your help has saved me hundreds of hours of internet surfing.

First I like to thank you for your comment.

By example:

I click at one of the nodes in the treeview. (the value of the node is "Test")

I like to drag the value to a forms.textbox.1 (because I will drop the value at a specified place in the text)

When I use the default drag and drop actions the first two steps are going right but...

After this action the value, i have draged from the treeview,  is no longer available and visible in my treeview.
Scott McDaniel (EE MVE )

So your Drag event FROM the Treeview removes it from the Treeview?

If I'm not mistaken, there are several properties you can set for your Treeview that will allow you to "copy" instead of "cut" ... check the properties and see what you find.

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Scott McDaniel (EE MVE )

Right ... I knew there were some "option" settings available, but couldn't remember how to invoke them. I don't use the MS treeview anymore, so it's been a while since I've worked with it.
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Scott McDaniel (EE MVE )

Generally when a suggestion by an Expert helps you to solve your problem you would assign points to that Expert ...