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”?
If I do e.Data.GetData(DataFormats.FileDrop) I get a list of a bunch of filenames, as I should. Also, drag and drop works fine from Windows Explorer.
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;
}
}
You should take a look into e.AllowedEffect if
DragDropEffects.Copyis within the list.Update
Some time ago i also had some problems with getting the right format out of the
GetDataPresent(). Due to this fact, i just looked directly into the list provided byGetFormats()and did it on myself. The code was something like that:This simple solution works for me, but you could also walk all over the
GetFormats()array with linq and try to find your desired type byIEnumerable<T>.OfType<MyType>()or something similar.