简体   繁体   中英

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM