private void listBox_DragDrop(object sender, DragEventArgs e)
{
ListBox targetListBox = (ListBox)sender;
List<string> items = targetListBox.Items.Cast<String>().ToList();
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
if (!File.Exists(file))
continue;
string fileName = Path.GetFileName(file);
try
{
int targetIndex = items.IndexOf(items
.Where(itemText => itemText.StartsWith(fileName))
.First());
items[targetIndex] = String.Format("{0} ({1})", fileName, file);
log.InfoFormat("Updated {0} on {1}.", fileName, targetListBox.Name);
}
catch (InvalidOperationException)
{
items.Add(String.Format("{0} ({1})", fileName, file));
log.InfoFormat("Added file {0} to {1}.", file, targetListBox.Name);
}
catch (ArgumentNullException)
{
items.Add(String.Format("{0} ({1})", fileName, file));
log.InfoFormat("Added file {0} to {1}.", file, targetListBox.Name);
}
}
addItemsWithNaturalOrder(ref targetListBox, items);
}
private void checkedListBox_DragDrop(object sender, DragEventArgs e)