Geeks With Blogs
Beluga Consultancy

Ever get the idea that someone at Microsoft is just taking the piss?

I simply wanted to drag a row from a DataGridView onto a Trash Can picture and delete the row.

All the coding had already been done to delete the row so I expected to take 5 minutes knocking up the rest of it.

The PictureBox has DragEnter and DragDrop Event handlers so writing that bit was easy:

private void picDelete_DragDrop(object sender, DragEventArgs e)
{
deleteRow();

}

private void picDelete_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;

}

However a PictureBox doesn't have an AllowDrop property listed in the design time properties. Without this being set to true the Drag events will not be invoked and so the coding above will do nothing.

After a bit of searching I found some code where this was set at run time.

picDelete.AllowDrop = true;


However this property does not appear to exist when you enter the above code.

In spite of this it does actually compile and run successfully and now my PictureBox does exactly what I want.

Any logic in having hidden properties like this?

 

Posted on Friday, January 1, 2010 12:23 PM | Back to top


Comments on this post: DragDrop onto PictureBox C# 2008

# re: DragDrop onto PictureBox C# 2008
Requesting Gravatar...
This has been the case since Drag/Drop was added - try it in old VS2005, same thing. There was a fair bit of questioning when this was discovered (PictureBox inherits from Control, so the functionality is there - but the AllowDrop property is set to not browseable so does not appear in the settings). Microsoft's official line on this is that the PictureBox does not support (or is not intended to support, perhaps) drag and drop. Never heard a reasonable explaination as to why, but I guess there is a nasty bug waiting to happen at some point that is too difficult to fix (possibly something to do with dropping invalid image formats etc). There is special coding in to allow for Dropping on the form/parent and the picturebox is not supposed to interfere with it (i.e. drop an a panel that hold a picturebox and do all the processing at the panel level and it is supposed to ignore the picturebox and not cause DragLeave events when over it). I think so many people have coded around it - like you above - that it is unlikely they will remove it in future versions of the framework, so fairly safe.
Left by Richard on Jun 15, 2012 12:23 PM

Your comment:
 (will show your gravatar)


Copyright © BelugaNeil | Powered by: GeeksWithBlogs.net