I have been working on an app that formats an XML file into a TreeView and thought this bit of the code might come in handy for you.
This part enables you to drop an external file from your PC onto a TreeView (or any other control for that matter) where you can then do what you want with it. In my case just output the location.
Here you are:
1.
Change the AllowDrop property of your control to True
2.
Select the little lightning bolt in the Properties window and double-click the DragDrop and DragEnter events to create them in your code. Or just create them manually of course
3.
In the DragEnter event put this code:
Obviously you can extras to the allowed DataFormats such as Text, RTF etc.Code:e.Effect = e.AllowedEffect; if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; }
4.
In the DragDrop event add this code:
Code:if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string fileName in fileNames) { TreeView1.Items.Add(fileName); } }
Hey presto you got a tree view that you can drag files directly onto!
Obviously if you change this to a Text you can drag text directly onto it
Enjoy!![]()


Life is one big rock tune
Reply With Quote

