Friday, December 10, 2010

Dropping Files From Explorer to a ListBox

To enable drag and drop , we should set the allowdrop property of Listbox to True

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

}

private void listBox1_DragDrop(object sender, DragEventArgs e)
{
foreach (string fileName in (string[])e.Data.GetData(DataFormats.FileDrop))
{
listBox1.Items.Add(fileName);
}

}

0 comments:

Post a Comment