help with D+D and TreeView

  • Thread starter Thread starter SteveK
  • Start date Start date
S

SteveK

I want to make a little utility that will allow me to drag a folder onto a
treeView and then poppulate the treeView with the contents of the dragged
folder. So far things aren't going well. I have set AllowDrop to true and
added an event handler for DragDrop and in that handler added a MessageBox
to alert me that something was dropped.

The event never fires. I honestly don't know what to do from here, not many
options come to mind of things to explor. Anyone have any ideas? Clues?

Thanks!
Steve
 
Steve,

You need a handler for DragEnter as well, this handler is used to tell the
framework that you will accept the drag&drop, and also what drop operations
you can support. for example:

private void tvContent_DragEnter(object sender,
System.Windows.Forms.DragEventArgs e)
{
if( e.Data.GetDataPresent("FileDrop") )
e.Effect = DragDropEffects.Copy;
}

This example is from a similar app I wrote a few years ago, but it should
still be relevant. Note that you pass back your supported effects via
e.Effect, and you can also set this to DragDropEffects.None if your code
decides that the drop cannot be handled for some reason.

Hope this helps,
Chris
 
Back
Top