e.Data.GetDataPresent not working in WinForms drag-and-drop handler?
Posted
by jnylen
on Stack Overflow
See other posts from Stack Overflow
or by jnylen
Published on 2010-05-17T16:31:29Z
Indexed on
2010/05/17
18:20 UTC
Read the original article
Hit count: 1032
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;
}
}
© Stack Overflow or respective owner