.NET ListView 选定问题
我正在尝试在单个选择 ListView
中选择一个项目。我知道您应该通过将项目的 Selected
属性设置为 true
来完成此操作。
到目前为止,一切正常,但当我将 Selected
设置为 true 时,SelectedItems
集合不会更新,并且 SelectedIndexChanged
事件不会触发。当操作 SelectedIndices
列表时,我遇到了同样的问题:没有事件,没有集合更新。
有什么想法吗?
需要明确的是,该事件被触发,但在 Selected
更改后发生了未定义的时间。 ItemSelectedChanged
事件也是如此。我正在开发 WinForms 应用程序。
I am trying to select an item in a single select ListView
. I know you should do it by setting the Selected
property to the item to true
.
Everything works fine so far but when I set Selected
to true, the SelectedItems
collection is not update and the SelectedIndexChanged
event is not fired. When manipulating the SelectedIndices
list I get the same problem: No event, no update of the collection.
Any ideas?
Just to make clear, the event is fired but it happens an undefined ammount of time after Selected
is changed. Same is for ItemSelectedChanged
event. I am working on a WinForms app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(假设您正在谈论 WinForms 应用程序)
我可能是错的,但根据我的经验,ListView 的 SelectedIndexChanged 事件并不像您想象的那么可靠。我认为你最好使用 ItemSelectionChanged 事件。
有趣的链接:
http://jerryandcheryl.net/jspot/2009/01/listview- selectedindexchanged-vs-itemselectionchanged/
(assuming you are talking about a WinForms application)
I may be wrong, but from my experience the ListView's SelectedIndexChanged event is not as reliable as you might think it would be. I think you'd better use the ItemSelectionChanged event.
Interesting link:
http://jerryandcheryl.net/jspot/2009/01/listview-selectedindexchanged-vs-itemselectionchanged/