0
votes

I have written a small C# form application that I will use to view some binary files data. I would like to be able to drag and drop files from windows explorer into the application and load them accordingly. I know there are several related questions on SO about D&D, and I have followed their suggestions about running my app as a normal user / administrator, but I cannot ever make the event for drag and drop fire.

Here is where I set the allow drop bit & add the event handler to the control (in InitializeComponent()):

        this.dataGridView1.AllowDrop = true;
        this.dataGridView1.AllowUserToOrderColumns = true;
        this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        this.dataGridView1.Location = new System.Drawing.Point(12, 33);
        this.dataGridView1.Name = "dataGridView1";
        this.dataGridView1.Size = new System.Drawing.Size(916, 119);
        this.dataGridView1.TabIndex = 0;
        this.dataGridView1.DragDrop += new System.Windows.Forms.DragEventHandler(this.dataGridView1_DragDrop);

I can set a breakpoint in this.dataGridView1_DragDrop, but it simply never fires. Ontop of that, the mouse icon is invariably a circle with a score through it when ever I am dragging a file over my application. I have also tried to add the event handler for drag drop to my form, and pointed it to the same event handler method as my data grid view (and set the AllowDrop bit on the form). This to results in identicle behavior. What am I missing?

1

1 Answers

3
votes

You must set the e.Effect property on the 'DragEnter' event as specified in http://msdn.microsoft.com/en-us/library/aa984430(v=vs.71).aspx