Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
In my windows application i have a listbox on the form. What i want is that when i drag and drop single or multiple files on listbox from the explorer, the absolute paths of the files should get added in the listbox.

But the problem is that the drag operation is not being supported. All i want is that somehow the event gets trapped and i should be able to access the names of the files draged in the listbox.The dragover, dragenter and dragleave events are being fired but no useful information can be retrieved from the 'e' parameter of the event.

Please help me implement this.

And if it is not possible with the listbox and with a richtextbox, even that will work.

Framework- .net 3.5
Software- Visual Studio 2008
Posted

Have a look at this article:
Drag and Drop files from Windows Explorer to Windows Form[^]

Good luck!
 
Share this answer
 
Comments
Rahul_Patel 18-Apr-11 10:50am    
Thanks sir.......
E.F. Nijboer 18-Apr-11 10:57am    
Your welcome :-)
C#
public Form1
{
    InitializeComponent();
    listBox1.AllowDrop = true;
    listBox1.DragEnter += new DragEventHandler(listBox1_DragEnter);
    listbox1.DragDrop += new DragEventHandler(listBox1_DragDrop);
}

private void listBox1_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Copy;
}

private void listBox1_DragDrop(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
       {
           string[] fileName = (string[])e.Data.GetData(DataFormats.FileDrop, true);
           listBox1.Items.Add(fileName);
       }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900