Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I maintain the file order in Windows Explorer when drag and dropping files into wpf/C# application?

In my application the user can drag and drop files from windows explorer onto a listbox in my application. This all works excellent however when dragging multiple files, depending which file the user clicks in windows explorer to begin dragging, the order the files passed will differ when calling:

e.Data.GetData(DataFormats.FileDrop)

How do I receive the files in the same order as they are displayed in windows explorer?

Thanks for your help!

like image 812
Chris Daviduik Avatar asked May 25 '11 18:05

Chris Daviduik


2 Answers

If you shift-select a bunch of files from 0000 to 0010 and then drag them into an application (say video files and drag them into VLC). Explorer will feed the list not in the order you selected the items but from the item you left-click-n-dragged from.

Click on 0000 and they will show up in number order. Click on 0003 and they will show up from 0003 to 0010 and then 0001 and 0002

So the correct way to "drag n drop" is to always drag from the top.

like image 79
Mårten Woxberg Avatar answered Oct 17 '22 08:10

Mårten Woxberg


The order you receive them is the order in which they were selected. I encountered this problem once before and as far as I was able to tell you cannot get them in Explorer's sort order.

Therefore your code should assume the user selected them in that order for a reason.

like image 20
user7116 Avatar answered Oct 17 '22 07:10

user7116