views:

31

answers:

1

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;
    }
}
A: 

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.

Hans Passant
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
It's just an example :)
Hans Passant
yes... but what cast do I have to use to get the File and its real data ? byte[] ?
Panella
You only the get path to the file. Reading the file requires writing code. Like File.ReadAllBytes().
Hans Passant