C# 中的 openfiledialogue 正在选择多个值,但它选择最后一个选定项作为第一个
当我面临这个问题时,有人可以指导我吗?
我有一个应用程序,我可以在其中通过浏览按钮引入项目,现在当用户选择多个文件时,尽管它选择了它们并添加它们(因为 multiselect = true),但它选择了顶部的最后一个选定项目,为什么?
因此导致流程错误。
Can anyone guide me as I am facing this issue?
I have a app in which I can bring items through a browse button, now when a user selects multiple files , though it selects them and add them (because multiselect = true) but it is selecting the last selected item at the top why?
Therefore causing the flow to be wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果没有看到相关代码,问题可能是另一个问题,但为了让您意识到,有两种获取输出的方法:使用
文件名
,或文件名
。如果启用
MultiSelect
但只查看FileName
属性,您将只能获得一个文件的名称,嗯,两种方式确实是一种简化,因为您还有
SafeFileName
和SafeFileNames
。我将把研究留给读者作为练习。我可能根据评论误解了您的问题,但让我们看看。
Without seeing the relevant code, the issue could be a different one, but just to make you aware, there are two ways of getting the output: either using
FileName
, orFileNames
.If you enable
MultiSelect
yet only look at theFileName
property, you will only get the name of one file,Well, two ways is a simplification really, because you also have
SafeFileName
andSafeFileNames
. I'll leave the research into such as an exercise for the reader.It's possible I have misinterpreted your problem based on comments, but let's see.
您没有说明为什么顺序对您很重要,以及您是否确实需要按照用户选择文件的顺序进行排序。
但如果不这样做,您可以简单地按名称对选定的文件进行排序:这为您提供了有意义的可预测排序顺序。
You didn't say why the order matters for you and if you really need it in the same order as the user selected the files.
But if you don't, you could simply sort the selected files by their name: this gives you predictable sort order that makes sense.
该对话框首先返回焦点文件名(带有虚线边框的文件名,这是您最近单击的文件名)。因此,如果您单击一个文件名,然后按住 Shift 键并单击列表中较低的一个文件名,则最后一个文件将成为焦点文件,并且它位于列表中的第一个文件名,然后按顺序依次是其他文件名。
如果您以相反的方式执行此操作 - 单击一个,然后按住 Shift 键单击列表中的上一个 - 那么它们将按您期望的顺序列出。
如果您不按住 Shift 键并单击,而是在要选择的文件周围拖动一个矩形,也会出现同样的情况。这不会改变焦点(焦点将保留在列表中的第一个文件名上),因此它们按照列表中显示的顺序排列。
如果用户开始使用键盘(Shift+向上/向下、Ctrl+空格、Ctrl+向上/向下),或者使用 Ctrl+单击选择不相交的范围,则还有更多内容,但底线是,顺序全部取决于用户,以及他们如何选择文件。
但你到底为什么关心文件列出的顺序呢?您实际上应该将其视为无序列表(因为用户实际上没有好的方式来指定顺序 - 这不是对话框的意图,因此它从未被设计为使其轻松订购您的选择)。如果您想按字母顺序或其他某种顺序显示文件名,则只需对返回的列表进行排序即可。
The dialog returns the focused filename (the one with the dotted-line border, which is the one you clicked most recently) first. So if you click on one filename, and then Shift+Click on one lower in the list, the last one becomes the focused one and it's first in the list, followed by the others in order.
If you do it the other way around -- click one, then Shift+click one higher in the list -- then they'll be listed in the order you expect.
Same thing if you don't Shift+click, but instead drag a rectangle around the files you want to select. That doesn't change the focus (which will stay on the first filename in the list), so they're in the order they're shown in the list.
There's more to it if the user starts using the keyboard (Shift+Up/Down, Ctrl+Space, Ctrl+Up/Down), or selecting disjoint ranges using Ctrl+click, but the bottom line is, the order is all up to the user, and how they go about selecting the files.
But why on earth do you care what order the files are listed? You should really just be treating this as an unordered list (because there's really no good way for the user to specify the order -- that's not the intent of the dialog, so it was never designed to make it easy to order your selection). If you want to show the filenames in alphabetical order, or some other kind of order, then just sort the list you get back.