.NET ListView 选定问题

发布于 2024-12-20 11:23:41 字数 453 浏览 4 评论 0原文

我正在尝试在单个选择 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 技术交流群。

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

发布评论

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

评论(1

离去的眼神 2024-12-27 11:23:41

(假设您正在谈论 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/

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