
Treeview Problem - I just can't see it..
Hi,
I was wondering if anyone can tell me where I'm going wrong?
I have a treeview and listview control and I am trying to allow the user
to drag and drop an item from the listview to the treeview control. I
have managed to get this much to the work but the problem is that the
selected items never drop in the correct location. They will either
drop in as a child node in the last created node (I am populating the
treeview from a sqlserver table) or else they drop as child of the Root
node.
Below is the code I've been playing with (pardon the mess) but I am
obviously missing something here as I just can't get it to work at the
moment. I've tried several combinations I came across on this newsgroup
but no joy so far.
Any help or suggestions would be good.
Thanks.
-------------------------------------------------------------------
Private Sub TreeView1_DragDrop(Source As Control, x As Single, y As Single)
Dim DragItem As ListItem 'Listview item that was dragged
Dim NewNode As Node 'New treeview node
'Dim DropNode As Node 'Node that the dragged item was dropped on
If TypeOf Source Is ListView Then
'Set DropNode = TreeView1.DropHighlight
'Set DropNode = TreeView1.SelectedItem
' Set gnode = TreeView1.DropHighlight
' Set gnode = TreeView1.SelectedItem
TreeView1.SelectedItem = TreeView1.DropHighlight
'Assign the selected item from the listview to 'DragItem'
Set DragItem = ListView1.SelectedItem
'Add a new child node to the node that was selected for
the drop
'Set gnode = TreeView1.Nodes.Add(gnode, tvwChild,
ListView1.SelectedItem.Text, ListView1.SelectedItem.Text)
Set NewNode = TreeView1.Nodes.Add(gnode, tvwChild,
ListView1.SelectedItem.Text, ListView1.SelectedItem.Text)
'Remove the selected list item from the listview
Source.ListItems.Remove (DragItem.Index)
'Remove the drophighlight from the treeview
Set TreeView1.DropHighlight = Nothing
End If