.netwinformslistviewvirtualmode

How do I update a WinForms ListView when using VirtualMode=True?


I have an app with a large ListView which is terribly slow so I'm implementing VirtualMode. MSDN does not seem to cover how I would add and delete new items in the middle of the listview.

For example, the ListView has 1000 items (representing files on disk) and after the initial population of the ListView (by the RetrieveVirtualItem event) some files will be deleted and some added so that VirtualListSize might even be the same after the update.

Question 1) How do I say to the ListView 'these items have been changed/deleted' so that it requeries?

Additionally, some of files just change and I'd like to reflect their changed status in the listview.

Question 2) How do I find an item in the listview given that VirtualMode does not let me access the Items collection that I was using before (I used the ContainsKey method on that collection).

Sounds easy, but I can't see it myself. Help greatly appreciated.

Ryan


Solution

  • To add or delete items, simplay set VirtualListSize to the total count of items. To refresh individual items use RedrawItems.

    To locate a particular item, you use the container you already have, don't go back to the ListView. The indicies within your list should match up with the items from the ListView.