e.Data.GetDataPresent not working in WinForms drag-and-drop handler?
- by jnylen
I'm trying to drag files into my application from a program called Locate32 (which is great by the way). Here is what happens:
e.Data.GetFormats()
{string[7]}
[0]: "FileDrop"
[1]: "FileNameW"
[2]: "FileName"
[3]: "FileNameMap"
[4]: "FileNameMapW"
[5]: "Shell IDList Array"
[6]: "Shell Object Offsets"
DataFormats.FileDrop
"FileDrop"
e.Data.GetDataPresent(DataFormats.FileDrop)
false
Why does e.Data.GetDataPresent(DataFormats.FileDrop) return false even though FileDrop is clearly one of the formats listed as "available"?
Drag and drop works fine from Windows Explorer. If I do e.Data.GetData(DataFormats.FileDrop) I get a list of a bunch of filenames, as I should.
Here's the code for my DragEnter handler:
private void MyForm_DragEnter(object sender, DragEventArgs e) {
if(e.Data.GetDataPresent(DataFormats.FileDrop)) {
e.Effect = DragDropEffects.Copy;
} else {
e.Effect = DragDropEffects.None;
}
}