Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag and Drop from ListBox to TreeView

Status
Not open for further replies.

Hexonx

Programmer
Jan 10, 2001
102
US
I am trying to drag an item from a ListBox and drop it on a TreeView but can't get any drag events to fire on the TreeView. Here's the core code:

Private Sub lstItems_MouseDown(...)
lstItems.OLEDrag
End Sub

Private Sub lstItems_OLEStartDrag(...)
Data.Clear
Data.SetData lstItems.Text, vbCFText
AllowedEffects = vbDropEffectMove
End Sub

In each OLE drag event on the TreeView I have a comment place marker and breakpoint, but none of these events fire.

When dragging from ListBox, the cursor changes to a "not allowed" cursor (I'm not setting the cursor myself).

I notice that the TreeView takes a MSComctlLib.DataObject and the ListBox a DataObject. This may have something to do with it.

Any ideas? I am stumped!
 
I found it. The OLEDropMode was set to the default ccOLEDropNone. I set it to ccOLEDropManual. In addition, I added the following code:

Private Sub TV_OLEDragOver(...)
Dim oNode As Node

' If mouse is over a node, set that node
' as the selected node.
Set oNode = TV.HitTest(x, y)
If Not oNode Is Nothing Then
Set TV.SelectedItem = oNode
oNode.Selected = True

' Prevents screen flickering from repeatedly setting
' .Expanded = True
If Not oNode.Expanded Then oNode.Expanded = True
End If
Set oNode = Nothing
End Sub

Private Sub TV_OLEDragDrop(...)
MsgBox "You dropped " & Data.GetData(vbCFText) & " on node " & TV.SelectedItem.Text
End Sub

Hope this helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top