Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView's DragEnter, DragOver, DragDrop event not raised (AllowDrop=True)

This one is very weird:

My app works just fine, but suddenly the damn ListView control's events are not raised any more. It just comes and goes without any clear reason. (Obviously) I've set the AllowDrop property to True and handled the DragEnter, DragOver and DragDrop events as follows:

Private Sub lstApplications_DragDrop(ByVal sender As Object, ByVal e As    System.Windows.Forms.DragEventArgs) Handles lstApplications.DragDrop, Me.DragDrop
    m_fileNames = CType(e.Data.GetData(DataFormats.FileDrop), String())
    mnuType.Show(Cursor.Position, ToolStripDropDownDirection.BelowLeft)
End Sub

Private Sub lstApplications_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstApplications.DragEnter, Me.DragEnter, lstApplications.DragOver, Me.DragOver
    If chkMode.Checked OrElse Not e.Data.GetDataPresent(DataFormats.FileDrop, True) Then
        e.Effect = DragDropEffects.None
    Else
        e.Effect = DragDropEffects.Copy
    End If
End Sub

It doesn't matter what code I wrote in these two methods because none of the events are raised. Is there anything I'm missing here?


I run the same app on another machine and it worked just fine. I then restarted my own machine and everything started working again. I'm not sure, but seems like something was wrong with Windows.

like image 706
TheAgent Avatar asked Feb 17 '09 14:02

TheAgent


3 Answers

I just had hours of misery with a similar problem. three mandatory requirements for drag and drop to work:

  1. Make sure your target UI Element has AllowDrop="True", you don't need this for the entire App, just the element you want want to enable.
  2. Some elements do not receive certain mouse events (including d&d) if their background is not set. Background="Transparent" will do.
  3. Running any program with Administrator privileges will mess with drag and drop. make sure you start visual studio without administrator privileges.
like image 181
Slime recipe Avatar answered Sep 18 '22 01:09

Slime recipe


I've had this problem when running Visual Studio 2008 on Windows 7. VS2008 must run with admin privileges on Windows 7, so I'm running it as a different user. I'm pretty sure this prevents drag 'n' drop working as the application runs fine when run as an app, but drag 'n' drop won't work when being run from Visual Studio.

like image 33
RB. Avatar answered Sep 19 '22 01:09

RB.


Just remembered we have indeed seen this before, long time ago.

I believe it happens like this:

Drag and drop works fine until some user code throws an exception during a drag and drop operation.

The exception will be eaten; you won't get any error dialog (try it yourself and see). After this point, the drag and drop will stop working.

like image 30
Judah Gabriel Himango Avatar answered Sep 20 '22 01:09

Judah Gabriel Himango