从多选列表框中检索最近 SelectedItem 的值

发布于 2024-08-08 13:22:59 字数 153 浏览 1 评论 0原文

如何检索多选列表框中单击的项目的值?

目前,如果我单击一项并使用 lstBox.SelectedValue,它将返回正确的值;但是,如果我单击另一个项目,我仍然会显示第一个项目的值。

基本上,我想要最近单击的项目的值,无论它是否是 SelectedValue。

How can I retrieve the value of a clicked item in a multi-select listbox?

Currently, if I click one item and use lstBox.SelectedValue, it will return the proper value; however, if I then click on another item, I am still shown the first item's value.

Basically, I want the value of the item most recently clicked on, regardless of whether or not it is the SelectedValue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

空名 2024-08-15 13:22:59

如果是多选列表框,则可以使用 SelectedItems 而不是 所选项目

如果您需要知道选择项目的顺序,或者最近选择的项目的顺序,我认为您需要自己记录 SelectedIndexChanged 事件。

If it is a multiple selection listbox, you can get a collection of all the selected items by using SelectedItems instead of SelectedItem.

If you need to know the sequence in which the items were selected, or which was selected most recently, I think you would need to record if yourself by SelectedIndexChanged event.

菩提树下叶撕阳。 2024-08-15 13:22:59

当您选择/取消选择列表框中的项目时,将调用 SelectedIndexChanged 处理程序。

但是,它并不表明选择/取消选择了哪一个。

listbox1.SelectedItems

将包含当前选定的项目,您可以在内部跟踪最近添加的索引。

The SelectedIndexChanged handler will get called when you select/unselect an item in the listbox.

However, it doesn't indicate which one was selected/unselected.

listbox1.SelectedItems

will contain the currently selected items and you could internally keep track of which index was most recently added.

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