Solved

How to implement drag and drop text file path to treeview

Posted on 2006-06-09
3
246 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 60 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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