如何在虚拟模式下向 ListView 添加/删除项目?
如果我在虚拟模式下使用 ListView,那么据我了解,列表视图仅跟踪列表中的少量项目。当用户滚动时,它会动态地从虚拟列表中检索需要显示的项目。
但是,如果在主列表中添加或删除某个项目怎么办?如果在列表视图显示的索引范围之外添加/删除项目,那么我会假设当用户滚动到该索引时列表视图将显示添加/缺少的项目。这是正确的吗?但是,如果从用户当前正在查看的索引范围中添加/删除某个项目会怎样?如何触发列表视图刷新当前正在查看的项目以显示新的/丢失的项目?
仅供参考:我正在使用 ObjectListView 如果这有什么区别的话。
If I'm using a ListView in virtual mode then, as I understand it, the list view only keeps track of a small number of items in the list. As the user scrolls it dynamically retrieves items it needs to show from the virtual list.
But what if an item is added or removed from the master list? If an item is added/removed outside of the range of indexes being shown by the list view then I would assume the list view would show the added/missing items when the user scrolls to that index. Is this correct? But what if an item is added/removed from the range of indexes the user is currently viewing? How do I trigger the list view to refresh the items it is currently viewing to show the new/missing items?
FYI: I'm using an ObjectListView if that makes any difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虚拟列表对您的项目列表一无所知。它不会跟踪它们,即使是一小部分。它只会问“你想在第 n 行显示什么?”
如果您的主列表发生变化,您所需要做的就是重新绘制列表。
Invalidate()
将为您完成此操作。然后列表视图将再次询问您应该在控件中可见的每一行显示什么。如果您正在使用 ObjectListView,您是否考虑过使用 FastObjectListView,它既具有虚拟列表的速度优势,又具有普通 ObjectListView 的易用性?
A virtual list knows nothing about your list of items. It doesn't keep track of them, not even a small set. It only ever asks "what do you want to show at the n'th row?"
If your master list changes, all you need to do is redraw the list.
Invalidate()
will do that for you. The listview will then ask you again what it should show at every row visible in the control.If you are using ObjectListView, have you considered using the FastObjectListView which gives you the speed benefits of a virtual list and the ease of use of a normal ObjectListView?