nullable
nullable

Reputation: 2581

C# WinForms DragEnter never fires

I'm puzzled with this. I attempted implementing drag and drop on a DataGridView. Failing to see any events fired, I tried a simple form, with a text box.

I would like to be able to drag files or folders from Windows Explorer.

I'm missing something because these events never fire. I did read about DragEvents, Windows 7 and UIPI but I still couldn't get around this.

I'm out of ideas and I welcome your suggestions.

public Form1()
{
    InitializeComponent();
    this.AllowDrop = true;
    textBox1.AllowDrop = true;
    textBox1.DragEnter += new DragEventHandler(textBox1_DragEnter);
    textBox1.DragDrop += new DragEventHandler(textBox1_DragDrop);
    textBox1.DragOver += new DragEventHandler(textBox1_DragOver);
}

void textBox1_DragOver(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

void textBox1_DragDrop(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

void textBox1_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

It seems that this should work. I have a clean install on WP7 64 - with all updates, I don't have virus or malware protection running, or anything (to my knowledge) which could prevent these events firing.

Upvotes: 11

Views: 6929

Answers (2)

andyb
andyb

Reputation: 91

I found that while I was running my Forms application in debug mode from Visual Studio, it didn't work. Only when I ran it outside of VS does it work perfectly. Presumably this is also something to do with security on Windows 7 (and possibly later versions).

Upvotes: 5

fumble
fumble

Reputation: 476

I had the same issue. it was only because I was debugging from a "run as administrator" session. I think that since VISTA there is a security that prevents from dropping to a privileged application.

Upvotes: 46

Related Questions