syntaxEdit's DragDrop event not firing

Hi,
I have problem for implementing drag & drop on syntaxEdit. I’ve set:
syntaxEdit1.AllowDrop = true;
and:

        private void syntaxEdit1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect = DragDropEffects.Copy; // Okay
            else
                e.Effect = DragDropEffects.None; // Unknown data, ignore it
        }

and:

        private void syntaxEdit1_DragDrop(object sender, DragEventArgs e)
        {
            MessageBox.Show("DROPPED!");
        }

But after dropping a file into syntaxEdit, it seems that the DragDrop event is not fired!
Am I doing something wrong?

Thanks in advance

Hi,

You should also handle DragOver event the same way as DragEnter:

        private void syntaxEdit1_DragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect = DragDropEffects.Copy; // Okay
            else
                e.Effect = DragDropEffects.None; // Unknown data, ignore it
        }

DragDrop event can be handled like this:

        private void syntaxEdit1_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            if (System.IO.File.Exists(files[0]))
                syntaxEdit1.Text = System.IO.File.ReadAllText(files[0]);
            //MessageBox.Show("DROPPED!");
        }

Regards,
Andrew

1 Like

Hi Andrew,
Thanks so much