C# 中的 openfiledialogue 正在选择多个值,但它选择最后一个选定项作为第一个

发布于 2024-12-29 16:15:04 字数 150 浏览 0 评论 0原文

当我面临这个问题时,有人可以指导我吗?

我有一个应用程序,我可以在其中通过浏览按钮引入项目,现在当用户选择多个文件时,尽管它选择了它们并添加它们(因为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

×纯※雪 2025-01-05 16:15:04

如果没有看到相关代码,问题可能是另一个问题,但为了让您意识到,有两种获取输出的方法:使用 文件名,或 文件名

如果启用 MultiSelect 但只查看 FileName 属性,您将只能获得一个文件的名称,

此属性只能是一个选定文件的名称。如果你想
返回一个数组,其中包含所有选定文件的名称
多选对话框,使用FileNames

嗯,两种方式确实是一种简化,因为您还有SafeFileNameSafeFileNames。我将把研究留给读者作为练习。

我可能根据评论误解了您的问题,但让我们看看。

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, or FileNames.

If you enable MultiSelect yet only look at the FileName property, you will only get the name of one file,

This property can only be the name of one selected file. If you want
to return an array containing the names of all selected files in a
multiple-selection dialog box, use FileNames.

Well, two ways is a simplification really, because you also have SafeFileName and SafeFileNames. 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.

掩饰不了的爱 2025-01-05 16:15:04

您没有说明为什么顺序对您很重要,以及您是否确实需要按照用户选择文件的顺序进行排序。

但如果不这样做,您可以简单地按名称对选定的文件进行排序:这为您提供了有意义的可预测排序顺序。

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.

神经大条 2025-01-05 16:15:04

该对话框首先返回焦点文件名(带有虚线边框的文件名,这是您最近单击的文件名)。因此,如果您单击一个文件名,然后按住 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文