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

1

10

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.

Blairblaire answered 26/3, 2010 at 18:41 Comment(0)
W
9

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?

Warrin answered 27/3, 2010 at 0:4 Comment(2)
I'm loading individual thumbnails for each item in the list so I need to be notified when the user is viewing each item so I can preload the thumbnails. I'm trying to avoid loading all the thumbnails at once as I could potentially be showing a large number of items. Currently I am calling Build() to update the VirtualLIstView when my collection changes. Is there a reason I would want to call Invalidate() over Build()?Blairblaire
A virtual list is exactly the right approach to do what you want -- I've used exactly the same strategy. And BuildList() is best -- it call Invalidate() as part of its processing. Does it work?Warrin

© 2022 - 2024 — McMap. All rights reserved.