How to implement drag and drop text file path to treeview

  I've been looking with no luck.  But i want to add to my tree the capability to drag a file in windows explorer to my winform treeview node.  From which i would take the file fullpath and copy it over to my directory.  I just cant get any examples aside from moving from tree node to tree node.  Does anyone have examples on how to do this.  I'm using .net 2.0
Who is Participating?
Babycorn-StarfishConnect With a Mentor Commented:
Hi there,

after a bit of messing this works

        //Event handler for when you release the mouse button after dragging over
        private void treeView1_DragDrop(object sender, DragEventArgs e)
            Array a = (Array)e.Data.GetData(DataFormats.FileDrop);            
            if (a != null)
                int x = e.X;
                int y = e.Y;

                Point p = treeView1.PointToClient(new Point(x, y));

                TreeNode t = treeView1.GetNodeAt(p.X, p.Y);                
                MessageBox.Show("" + p.X + " , " + p.Y);
                t.Nodes.Add(new TreeNode(a.GetValue(0).ToString()));

        //Just so i have a node to work with
        private void Form1_Load(object sender, EventArgs e)

       //Causes the icon to change when you drag over the treeview
        private void treeView1_DragEnter(object sender, DragEventArgs e)
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect = DragDropEffects.Copy;
                e.Effect = DragDropEffects.Move;

Hopes this helps


have you seen this: ?

Can you already get the filename from Windows Explorer and for example display it in a message box?

and do you know how to copy from say a textbox to a specific node? (just checking before i start)


borg48Author Commented:
This was great thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.