Scott

Scott

  • NA
  • 2
  • 0

Drag and drop between listboxes and treeview, and within treeview help

Sep 21 2009 10:52 AM

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

Answers (2)