TreeView Drag/Drop Code

  • Thread starter David C. Holley
  • Start date
D

David C. Holley

Not having any luck with finding documentation & explanations on doing
drag/drop with a TreeView, I've started taking baby steps.

Question #1. How do I prevent a user from selecting a node that
shouldn't be dragged? Do I need to add code to the OLEStartDrag event to
somehow cancel it? Or is it another event? (The only nodes that should
be dragged are those with a .Tag of 'transport'.)

Question #2. Is there a way to change cursor image when the item being
dragged is dragged over an item to which it cannot be dropped?

Private Sub TreeView_OLEStartDrag(Data As Object, AllowedEffects As Long)

Debug.Print "OLEStartDrag"
Debug.Print Me.TreeView.Object.SelectedItem.Tag,
Me.TreeView.Object.SelectedItem.Key
Set selectedNode = Me.TreeView.Object.SelectedItem
Me!TreeView.Object.SelectedItem = Nothing

End Sub
 
A

Alex Dybenko

Hi David,

Question #1. How do I prevent a user from selecting a node that shouldn't
be dragged? Do I need to add code to the OLEStartDrag event to somehow
cancel it? Or is it another event? (The only nodes that should be dragged
are those with a .Tag of 'transport'.)

you can set AllowedEffects = 0 - this will cancel drag
Question #2. Is there a way to change cursor image when the item being
dragged is dragged over an item to which it cannot be dropped?

this is limited in Access, what you can do - is to set Effect = 2 in
OLEDragOver event
 
D

David C. Holley

I played around with the Effect value and found that Effect = 0 does
what I was wanting - namely to change the cursor to a zero with a slash
through it.

Question #3 - How do I make the TreeView control scroll down/up when
there are numerous nodes above & below out of view?
 
A

Alex Dybenko

Hi,
you can check in OLEDragOver event that y is near the edge, then set
m_iScrollDir to -1 or 1
then then use form timer event to scroll TV:

If m_iScrollDir = -1 Then 'Scroll Up
' Send a WM_VSCROLL message 0 is up and 1 is down
SendMessage moTV.hWnd, 277&, 0&, vbNull
ElseIf m_iScrollDir = 1 Then 'Scroll Down
SendMessage moTV.hWnd, 277&, 1&, vbNull
End If
 
A

Alex Dybenko

If y > 0 And y < 400 Then
'user move mouse near the top edge of treeveiw - scroll up
m_iScrollDir = -1
ElseIf y > (ctlTV.Height - 500) And y < ctlTV.Height Then
'scroll down
m_iScrollDir = 1
Else
m_iScrollDir = 0
end if

you can play with "zone height" to achieve better results
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top