?
Solved

How to implement drag and drop text file path to treeview

Posted on 2006-06-09
3
Medium Priority
?
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

771 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