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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag Listbox item intoTreeview 1

Status
Not open for further replies.

jibberski

Programmer
Aug 24, 2005
52
US
I'm trying to create child nodes in a treeview dragged in from a listbox. There have been two posts(archived) on this but no answers. I have read the MSDN on simulating the drag and drop also but concerned about dropping the "foreign" listbox object to the treeview. Does Anybody have this working or have any suggestions? Your help is very much appreciated.
 
I have not tried to do drag and drop from an external control, but I do not think that this would be a problem using a combination of simulated drag for the list box and real drop for the treeview. Notice on the OLEdragdrop event you have to check if a node was selected. In your case it will not be but just check that you have a Drag control selected using the simulated drag drop method.

Private Sub xTree_OLEDragDrop(Data As Object, Effect As Long, _
Button As Integer, Shift As Integer, x As Single, y As Single)

Dim oTree As TreeView
Dim strKey As String, strText As String
Dim nodNew As Node, nodDragged As Node

'Create a reference to the TreeView control.
Set oTree = Me!xTree.Object

'If nothing is selected for drag, do nothing.
If oTree.SelectedItem Is Nothing Then
Else
'Reference the selected node as the one being dragged.
Set nodDragged = oTree.SelectedItem
In your case this is a drag control using the simulated drag method Now modify all the nodDragged to be your properties from the control
'If the node was dragged to an empty space, update the
If oTree.DropHighlight Is Nothing Then
'Save the key and the text to use when you re-add the node.
strKey =
strText = nodDragged.Text
'Delete the current node for the employee.
oTree.Nodes.Remove nodDragged.Index
'Locate the record in the Employees table and update it.
rs.FindFirst "[EmployeeID]=" & Mid(strKey, 2)
rs.Edit
rs![ReportsTo] = Null
rs.Update
'Add this employee as a root node.
Set nodNew = oTree.Nodes.Add(, , strKey, strText)
'Add all the child nodes for this employee.
AddChildren nodNew, rs
'If you are not dropping the node on itself.
ElseIf nodDragged.Index <> oTree.DropHighlight.Index Then
'Set the drop target as the selected node's parent.
Set nodDragged.Parent = oTree.DropHighlight
'Locate the record in the Employees table and update it.
rs.FindFirst "[EmployeeID]=" & Mid(nodDragged.Key, 2)
rs.Edit
rs![ReportsTo] = Mid(oTree.DropHighlight.Key, 2)
rs.Update
End If
End If

'Deselect the node
Set nodDragged = Nothing

'Unhighlight the nodes.
Set oTree.DropHighlight = Nothing

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top