I have seen this everywhere and tried all the solutions and am not seeming to get what I want. I want to be able to drop files from explorer onto a ListView and then be able to sort them through drag and drop. I am have this simple code that gets the drag/drop from explorer.
this.messageView.AllowDrop = true;
this.messageView.Location = new System.Drawing.Point(12, 52);
this.messageView.Name = "messageGrid";
this.messageView.Size = new System.Drawing.Size(121, 97);
this.messageView.TabIndex = 3;
this.messageView.UseCompatibleStateImageBehavior = false;
this.messageView.DragDrop += new System.Windows.Forms.DragEventHandler(this.Form1_DragDrop);
this.messageView.DragEnter += new System.Windows.Forms.DragEventHandler(this.Form1_DragEnter);
and the handlers
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("FileGroupDescriptor"))
{
e.Effect = DragDropEffects.All;
}
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
messageView.Items.Add(e.Data.ToString());
}
This is bizarre, because of I change the messageView to a RichTextBox I have on my form, it works just fine. Are there additional steps that I have to do? When I attempt to drop onto the ListView, I get the circle with a line through it from Explorer. Any help would be appreciated. Thanks.
DragEnter and DragDrop events should be handled in the ListView, not in the Form.
About drag and drop: I do not remember the article name but I found a good example of it in codeproject.