2

Why is the dragdrop event never entered?

private void textBox1_DragDrop(object sender, DragEventArgs e)
{
    Array a = (Array)e.Data.GetData(DataFormats.FileDrop);

    e.Effect = DragDropEffects.All;
    Debug.WriteLine("were in dragdrop");
}

private void textBox1_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
    {
        e.Effect = DragDropEffects.All;
    }
}
Kara
  • 6,115
  • 16
  • 50
  • 57
Panella
  • 61
  • 1
  • 1
  • 6

1 Answers1

1

Change the e.Effect assignment to DragDropEffects.Copy. Double-check that the event assignment is still there, click the lightning bolt icon in the Properties window. Sample code is available in this thread. Note that you can cast to string[] directly.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • What If I would set the AllowDrop of the FORM/Window to false but the AllowDrop of the inner TextBox/DAtaGrid in the Form to True, is that working? I do not want to let user drop onto the form, just into the datagrid WITHIN the form. – Panella Aug 20 '10 at 08:11
  • yes... but what cast do I have to use to get the File and its real data ? byte[] ? – Panella Aug 20 '10 at 12:33
  • You only the get path to the file. Reading the file requires writing code. Like File.ReadAllBytes(). – Hans Passant Aug 20 '10 at 12:36