ptownbro985
New Member
- Joined
- Apr 3, 2012
- Messages
- 17
Trying to drag a child node only from a ActiveX TreeView Control to an ActiveX ListView control in VBA for Excel. It works occasionally, but something is wrong. I'm unable to consistently get the drag event to fire (sometimes it works, sometimes not) or, when it does, determine what was selected to add to the listivew.
My TreeView has the following nodes
-US (tag='parent')
-West (tag='parent')
-CA (tag='child')
-WA (tag='child')
-East (tag='parent')
-NY (tag='child')
-FL (tag='child')
In the above, I only want the drag to work on the nodes taged as 'child'. My attempted code is as follows:
My TreeView has the following nodes
-US (tag='parent')
-West (tag='parent')
-CA (tag='child')
-WA (tag='child')
-East (tag='parent')
-NY (tag='child')
-FL (tag='child')
In the above, I only want the drag to work on the nodes taged as 'child'. My attempted code is as follows:
Code:
Dim MyTreeNode As Node
Dim MyText As String
Private Sub TreeView1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As stdole.OLE_XPOS_PIXELS, ByVal Y As stdole.OLE_YPOS_PIXELS)
Dim MyDataObject As DataObject
Dim Effect As Integer
If Button = 1 Then
'For some reason this executes multple times even though I'm only picking one node.
Debug.Print TreeView1.SelectedItem.Text
If InStr(1, TreeView1.SelectedItem.Tag, "Child") > 0 Then
Set MyTreeNode = TreeView1.SelectedItem
Set MyDataObject = New DataObject
MyText = TreeView1.SelectedItem.Text
MyDataObject.SetText MyText
Effect = MyDataObject.StartDrag
End If
End If
End Sub
Private Sub ListView1_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MyListViewItem As ListItem
Set MyListViewItem = ListView1.ListItems.Add(1, "M" & MyTreeNode.Key, MyTreeNode.Text)
End Sub