How do I add/remove items to a ListView in virtual mode?

不羁的心 提交于 2019-12-19 02:08:56

问题


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.


回答1:


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?



来源:https://stackoverflow.com/questions/2525828/how-do-i-add-remove-items-to-a-listview-in-virtual-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!