views:

528

answers:

1

C#: How would you only draw certain ListView Items while in Virtual Mode?

I am trying to create a filter-like feature to use in listview so that if the user selects an imageindex from 0-5, it will loop through the listview items and only make it so that the items in question with the correct image index will be displayed and the other items will be hidden. How would I go upon creating such a routine?

A: 

If you are already using the Virtual Mode for the grid, you know that all items shown in the list are requested from the "RetrieveVirtualItem" event of the list. This means that you should already have an array of objects as the back layer for the list items (the front layer). In order to apply the filter you desire, you just have to maipulate the event handler for the envent above mentioned and using an external variable holding the filter, only return the items that meet the condition.

Please let me know if you need more details, maybe provide some code for me to specifically help you on,

AlexDrenea
That's pretty much exactly what I want to do and tried, but when I try to only retreive specific items from the cached array variable ListViewItems[] I receive an error. I'm a bit confused as to how to go upon it since I thought that event would return an exception if it does not return an object, so how would I make it so it ignores the ones I don't want to display so that it doesn't fire the event for those?
Can you plese detail what error it throws?I think you have a little missunderstanding: the event is not fired for every ListViewItem youhave in the chached list. The event is fired by the list for every position of the list it has to show. So every time the event is fired, you need to provide your next item from the array or nothing if no other item is available.
AlexDrenea
So should I create another ListViewItem array or just an int array to keep track of which index(s) I only want retrieved back into listview from the RetrieveVirtualItem event?
So in the button that will commence the filtering what shall I initially do so that RetrieveVirtualItem is only fired off for the items I want displayed from the arrListViewItemCache[]? And when I'm done with the filtered view, how would I redraw them back so that they all show again in the listview? By using the invalidate method?