Hello.

I'm having a bit of difficulty implementing Drag and Drop.

The scenario is this.
I have a project with an MDI child where I want to drop documents from Windows Explorer.

The code is all in place (this is just for debugging purposes) and I have set AllowDrop to True for the form.

Private Sub Registrations_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                e.Effect = DragDropEffects.All
            End If
        End Sub

        Private Sub Registrations_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                Dim files() As String

                files = e.Data.GetData(DataFormats.FileDrop)
            End If
        End Sub

But whenever I grab onto a file and drag it onto the form, I get the "Not Here" cursor (you know, the circle with a slash through it), and thus cannot drop the file.

What am I missing?
I'm using Visual Studio 2008 Pro in Windows 7, if that has anything to do with it.

Yes. I saw that excellent article.
And it's practically identical to what I'm trying to achieve.
But alas, I still get that pesky little "Not Here" cursor.

I read another article shortly after posting this question, that this has something to do with differences in elevated securities. Especially on Vista and Windows 7.
On Windows XP, this is appearently not an issue.
So, I was kind of hoping for a solution on this. :)

Hi,

Because I'm using still Windows XP, I can't do some test to try to help you on this.
That's why I gave you that link in the hope it could help you.

I managed to solve it.
Although I cannot debug this functionality, it still works when compiled.

If you add <requestExecutionLevel level="asInvoker" uiAccess="false" /> in your manifest file. It will work.

I hope the following can help:

When converting an app from Net 1.1 to 3.5, dragdrop stopped working on a form that allowed users to drag items from a list to a RichTextBox.

You could drag from outside the app (EG: From WordPad to the app’s Richtestbox), but you could not drag from withing the form.

The web holds ample complaints on this, but no solution prevailed until a hint was found here:

http://social.msdn.microsoft.com/forums/en-us/vblanguage/thread/173FD7B1-08D7-484E-920F-30E2ADD151E3

Adding the DragOver event to the DragEnter event's handles clause seems to fix the problem.

Interesting to note that intellisense does not offer the dragover event - you have to manually enter it.

Even more strange, the object browser does not show DragOver as a valid event - WTF!

Also, Allowdrag is not available in the proprties window for RichTextBoxes. You have to set this property in code on app init.

As I already stated. I managed to solve the problem, and it is now fully functional.
On Windows XP this is not an issue, but on Vista/7 it is.

Thank you for your tip, but it doesn't apply.
My app is completely done in .NET 2.0 from scratch, and my problem involed dragging files from the explorer onto the form itself, regardless of how many controls there are on it.

For others out there, here's the solution.
As a normal user on Vista/7, the standard functions in file management are working in the lowest security "settings".
So, when you create an application and decide to run it in an elevated "administrative" environment, then the difference in the standard lower security windows functions and your application will cause the UAC to get itself involved, in order to prevent whatever event it deems a security risk to trigger.
So, to fix this, just add this to the file app.manifest, and set the file as Embedded Resource:

<security>
   <requestedPrivileges>
      <requestedExecutionLevel level="asInvoker" />
   </requestedPrivileges>
</security>

NOW you can drag-and-drop between Windows and your application, because the program will be run as you, the normal user.

This question has already been answered. Start a new discussion instead.