多个文件拖拽时,文件的排序问题

来源:百度知道 编辑:UC知道 时间:2024/06/30 10:49:20
用VS2008开发桌面程序时,添加了拖拽功能。但选中多个文件拖拽时,有个文件顺序的疑惑.
先说说我的实现方法吧:
首先在Windows窗体中注册了DragOver事件,然后在该事件中,添加下面语句。
// Code start
string[] fileNameList = (string[])e.Data.GetData(DataFormats.FileDrop);
// Code end
这样便可以获得拖拽文件的的fileNameList.
经过测试, 这个fileNameList对象中的顺序, 和直接拖拽的文件,及文件名排序有关,而和选择文件时的先后顺序无关。(这是Debug的结果,并没有找到官方的说明)
不知道这个fileNameList的顺序,是否有个官方的说法。
我希望 fileNameList的顺序,就是拖拽前文件选择的先后顺序。这个功能能实现吗?

Hello pettypower,

I don't think there's a way to do that - although I'm not exactly sure for
which order you're asking:
This sounds like two different things to me - the order that is shown in
Explorer vs. the order in which files were selected. As far as I remember,
the order of file/dir info being passed in would actually be the same as
the order in which they were selected, but I could be wrong - in any case
I don't think that this is part of the spec, and so I wouldn't rely on it.

My recollection is that Windows Explorer multi-file select goes something like this:
1) Files are added to the file list LIFO. The most recently selected
file is first in the list.
2) When selecting more than one new file at a time (drag-rect,
shift-select a list, etc), the group is in order according to how they
appear in Windows Explorer, but the whole group is added at the front of
the selectio