从多选列表框中检索最近 SelectedItem 的值
如何检索多选列表框中单击的项目的值?
目前,如果我单击一项并使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果是多选列表框,则可以使用 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.
当您选择/取消选择列表框中的项目时,将调用 SelectedIndexChanged 处理程序。
但是,它并不表明选择/取消选择了哪一个。
将包含当前选定的项目,您可以在内部跟踪最近添加的索引。
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.
will contain the currently selected items and you could internally keep track of which index was most recently added.