lynn osler

lynn osler

  • NA
  • 25
  • 5.1k

Drag n Drop files into listbox but not duplicate files?

Aug 3 2011 12:38 PM
I am building a drag and drop that will drag a file into a listbox and "tooltip" the file location.  Right now, I am trying to get it so that if the file is already there, it won't add it, but give a pop up saying it is there.  Here is my code. 




 




public partial class MainWindow : Window{
 
 public


 {
 InitializeComponent();
 }


MainWindow()public MainWindow()private void filesDropped(object sender, DragEventArgs e)

 if (e.Data.GetDataPresent(DataFormats.FileDrop))



 {
 string[] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true) as string[];
 foreach (string droppedFilePath in droppedFilePaths)
 {


 ListBoxItem fileItem = new ListBoxItem();
 
 
fileItem.Content = System.IO.Path.GetFileNameWithoutExtension(droppedFilePath); 
fileItem.ToolTip = droppedFilePath;
 DropListBox.Items.Add(fileItem);




 }


}









Answers (8)