Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DragnDrop file in DataGridView

I have the following DataGrid of name gridOperations. I have set AllowDrop to true, and used the following code:

private void gridOperations_DragDrop(object sender, DragEventArgs e)
{

    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
        var files = (string[])e.Data.GetData(DataFormats.FileDrop);
        foreach (var filePath in files)
        {
            MessageBox.Show(filePath);
        }
    }

}

private void gridOperations_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
        e.Effect = DragDropEffects.All;
    else
        e.Effect = DragDropEffects.None;
}

but when I try to drag file into the DataGrid, it gives me the 'STOP' cursor. What am I doing wrong?

Is is possible because it's binded to List?

Basically what I need is to get the filename from file dragged into the datagrid and determinate in which cell its dragged into.

like image 625
Kristian Avatar asked Nov 12 '22 16:11

Kristian


1 Answers

Are your grid and all the parent controls enabled?

Your code is correct and it works. The only thing I can think of is that your GridView may not be enabled. Can you change the current row of the grid by clicking when the application is running?

like image 182
Mohammad Dehghan Avatar answered Nov 15 '22 06:11

Mohammad Dehghan