Home > Blockchain >  Post DragDrop event in datagridview C#
Post DragDrop event in datagridview C#

Time:10-11

I have a main form inside of it i am using datagridview, also i am using the dragdrop event for the datagridview to drop files in my datagrdiview, once i drop the file in the datagridview, another form shows to select what is data the user wants to display and arrange of the data .. etc

when my second form shows i want it to be focused exactly like the effect of this code child.ShowDialog(); means the user can not click the main form until he finish this form

but if i use the above code in the middle of the DragDrop event, the mouse cursor outside of the main form will have the effect of DragDropEffects.Copy; and even the folder i dragged the file from freezes until i close the second form

i understand this happening because of ShowDialog() here is my code for the dragdrop events.

private void dataGridView1_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
        e.Effect = DragDropEffects.Copy;
    }
    else
    {
        e.Effect = DragDropEffects.None;
    }
}
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
        Form2 child = new Form2();
        child.ShowDialog();
    }
}

my question is : Is there any post dragdrop event so once the user release the mouse and i get the file name from the drag drop operation, then i can show form2?.

Here is an image of the cursor outside my application.

enter image description here

EDIT: According to Jimi comment, the problem solved by using BeginInvoke(). This is the exact code i used

this.BeginInvoke((Func<DialogResult>)(() => child.ShowDialog()));

CodePudding user response:

According to Jimi comment, the problem solved by using BeginInvoke(). This is the exact code i used

this.BeginInvoke((Func<DialogResult>)(() => child.ShowDialog()));
  • Related