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

2019-02-13 01:41发布

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条回答
叼着烟拽天下
2楼-- · 2019-02-13 02:32

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?

查看更多
登录 后发表回答