I try to use VirtualMode in ListView but it never work.
I have set the VirtualMode = true, VirtualItemSize = 500, and implemented the RetrieveVirtualItem event. But at run time it always show the following error message:
ListView virtualization requires a valid ListViewItem to be provided by the RetrieveVirtualItem event or in the OnRetrieveVirtualItem method.
This error message appeared twice, I have to lick “OK” to close the error dialog box twice.
I then able to access to my form. I then close my form by clicking the [ X ].
Finally, there is another error message appeared:
The component was not found.
I tried to look for an example or sample code on how to enable and use the Virtual Mode of ListView, but I cannot find any info related to this topic from the documentation web and samples from wisej web site.
Thanks and regards,
If you set the VirtualListSize to 500 your implementation of RetrieveVirtualItem has to return a ListViewItem for all 500. You cannot have a null item.
When VirtualMode is on, the items are not stored by the ListView. Every time the code requests an item the implementation will call RetrieveVirtualItem. It’s up to you to provide and cache the virtual items. The ListView doesn’t prefetch all the items, it only fetches the “page” requested by the client, which is about 100 items, so there is no way for the server or the client to know the total number of virtual items without VirtualListSize. If you set the VirtualListSize to 500, the client will know that there are 500 items but it will request only the first 100 and will keep requesting items as the user scrolls.
On the server side, every time your code uses the Items[index] collection, the implementation calls RetrieveVirtualItem. The best implementation is to create and cache virtual items processing the CacheVirtualItems event and then just return the items from your cache when processing RetrieveVirtualItems.
You can find a detailed explanation and example here: https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.virtualmode(v=vs.110).aspx
Thanks for the sample code. After I read the sample code, I can manage to make my program work with Virtual Mode.
However, I don’t know why I need to set the VirtualListSize equals to the number of items.
For example, my data source contains 28 records. If I set VirtualListSize to 500, it will fail. If I set VirtualListSize to 10, it will fail, too. I have to set VirtualListSize to 28, that is, same as the number of items to be created.
This is the same case in your sample code; The VirtualListSize is 5000000 in your sample, and you create 5000000 items.
So, what is the usage of VirtualListSize ? Why not the ListView detect the number of items in the ListView.Items collection and set it automatically and internally, as it can’t be any value other than ListView.Items.Count ?
Thanks and regards,
please find here a sample for virtual list view with 5.000.000 that we took
from the Mono test suite:
For the problems you have encountered, would it be possible to send us
a stripped down test case ? If yes, please send it to frankATiceteagroup.com
Thanks in advance !
Please login first to submit.