[英]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.在我的应用程序中,用户可以将文件从 windows 资源管理器拖放到我的应用程序的列表框中。 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:这一切都很好,但是在拖动多个文件时,这取决于用户在 windows 资源管理器中单击哪个文件开始拖动,调用时传递的文件顺序会有所不同:
e.Data.GetData(DataFormats.FileDrop)
How do I receive the files in the same order as they are displayed in windows explorer?如何以与 windows 资源管理器中显示的顺序相同的顺序接收文件?
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).如果您从 0000 到 0010 选择一堆文件,然后将它们拖到应用程序中(比如视频文件并将它们拖到 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.单击 0000,它们将按数字顺序显示。 Click on 0003 and they will show up from 0003 to 0010 and then 0001 and 0002单击 0003,它们将显示从 0003 到 0010,然后是 0001 和 0002
So the correct way to "drag n drop" is to always drag from the top.所以“拖放”的正确方法是始终从顶部拖动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.