Solved

How to implement drag and drop text file path to treeview

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now