Hi,
You want to drag files from a tree view in C# and open them up in Microsoft Word?
If so try this. You will basically need to create a new
DataObject and for all selected files in the treeview, add them to this DataObject using the
SetFileDropList method. You will need to wrap up the filenames in a
StringCollection which is passed to the SetFileDropList method.
Then start the drag and drop using the treeview
DoDragDrop method.
// need to use StringCollection
using System.Collections.Specialized;
// NOTE: attach the event (if not using Designer to do it...)
// this.treeView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView1_MouseDown);
// implement the MouseDown event to start drag and drop in tree view
private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
// this will test to see which node you have the mouse on - you can mod this to get all selected nodes
// we are assuming that the text of the node is the filename, for example C:\Test.doc.
TreeViewHitTestInfo tvhti = this.treeView1.HitTest(e.Location);
TreeNode tn = tvhti.Node;
// now wrap up the file(s) in a DataObject for Word to understand
DataObject obj = new DataObject();
StringCollection sc = new StringCollection();
sc.Add(tn.Text);
obj.SetFileDropList(sc);
// start the drag and drop
this.treeView1.DoDragDrop(obj, DragDropEffects.All);
}
Andez