?
Solved

How to implement drag and drop text file path to treeview

Posted on 2006-06-09
3
Medium Priority
?
253 Views
Last Modified: 2011-09-20
Hi,
  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
Thanks
0
Comment
Question by:borg48
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 16888458
Hi,

have you seen this:

http://www.codeproject.com/csharp/dragdrop.asp ?

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)


Cheers

BCS
0
 
LVL 11

Accepted Solution

by:
Babycorn-Starfish earned 240 total points
ID: 16889058
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()));
                //MessageBox.Show(t.Text);
            }          
        }

        //Just so i have a node to work with
        private void Form1_Load(object sender, EventArgs e)
        {
            this.treeView1.Nodes.Add("Root");
        }

     
       //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;
            else
                e.Effect = DragDropEffects.Move;
        }

Hopes this helps

BCS
0
 

Author Comment

by:borg48
ID: 16922045
This was great thank you
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question