Hey everybody, I was hoping to get a little bit of information. I've implemented drag and drop between the listboxes and treeview, but I'm having a tough time getting it done within the treeview itself. It will show the effect of moving, but it will not delete itself from the previous node, and implement itself in the new node.
I know it's something incredibly easy, but my brain is tired!
Here's the DragDrop code:
private void tree_procAssign_DragDrop(object sender, DragEventArgs e)
{
TreeView tree = (TreeView)sender;
Point pt = new Point(e.X, e.Y);
pt = tree.PointToClient(pt);
TreeNode nodeTodropIn = this.tree_procAssign.GetNodeAt(pt);
TreeNode nodeSource = (TreeNode)e.Data.GetData(typeof(TreeNode));
if (nodeTodropIn == null) { return; }
object data = e.Data.GetData(typeof(string));
if (data == null) { return; }
TreeNode tempNode = new TreeNode(data.ToString());
if (lbx_processorAssign.Items.Contains(data.ToString()))
{
if (nodeTodropIn.Level == 0)
{
nodeTodropIn.Nodes.Add(tempNode);
nodeTodropIn.Expand();
if (nodeTodropIn.Nodes.Contains(tempNode))
lbx_processorAssign.Items.Remove(data.ToString());
}
}
if (lbx_alphaAssign.Items.Contains(data.ToString()))
{
if (nodeTodropIn.Level == 1)
{
nodeTodropIn.Nodes.Add(tempNode);
nodeTodropIn.Expand();
if (nodeTodropIn.Nodes.Contains(tempNode))
lbx_alphaAssign.Items.Remove(data.ToString());
}
}
if (tree_procAssign.Nodes.Contains((TreeNode)e.Data.GetData(typeof(TreeNode))))
{
nodeTodropIn.Nodes.Add((TreeNode)e.Data.GetData(typeof(TreeNode)));
nodeTodropIn.Expand();
}
}
Any thoughts, or is anyone able to push me in the right direction?
Thanks!
Scott
Loading
Stephen YorkPosted Sep 27, 2009, 8:16 PM
I've got drag and drop going, but I'd like to give more visual feedback to my users.
Basically I need to be able to drag items to anywhere in the tree view. To insert between two items I could always just highlight one of them, the ask if the insert is to be before, after or overwriting the item, but I'd like to actually draw a horizontal line between the items when the mouse hovers between them.
Anyone know how to do this?
Thanks,
Steve
Roei BarPosted Sep 21, 2009, 2:26 PM
and here is a sample source code:
http://www.codeproject.com/KB/tree/treedragndropdemo.aspx