I have a listview control on a form. This listview control is populated with at times thousands of listviewitems.
Part of my process, is running through custom made filters, to hide unwanted items (before they're even inserted into the listview).
So as I hinted earlier, the way I hide items that I don't want is by not inserting them at all.
I'd like to make a shortcut available, that would allow me to show / hide the hidden items by simply pressing the shortcut.
My problem is that if I do this, I have to 'refresh' the listview items everytime as I do now ( by removing all and re-inserting the ones I want ).
Is there no faster / better way than by removing / re-inserting the items ( which takes roughly 2-3 seconds ); which is a noticeable-enough delay?
I was hoping for a 'visible' property on the listviewitem that I could set to true / false, but that property doesn't appear to exist.
As it stands, I have to resort to removing / re-inserting the new 'view' every time.
I hope I'm making sence.
Thanks for any help!
Unfortunately the ListView control does not have this capability. You might be able to inherit from the ListViewItem class and create your class that mimics this feature but otherwise you might be better served using a DataGridView control instead (which does support the ability to hide rows).
Paul ~~~~ Microsoft MVP (Visual Basic)
I recently had this issue myself.
I created a ListItem class that held all the information that I needed, I then stored these items in a Generic.Dictionary
then when needed populate the Listview with the relevant items to be shown.
alternatively, as suggested by Paul Clement go with the DataGridView which has the ability to hide rows, but beware that hiding rows still adds them to the datagridview, and if there are several 1000's this can have an effect on the speed of the DataViewGrid
Hope this helps.
Thanks Paul and Dogs. Those sound like viable options.
I'm kind of already doing your solution, Paul. I created my own visible property; when I 'hide' an item by setting the property, then it 'tells' my listview to refresh itself.
Still, when the listview refreshes itself, it's forced to remove / re-add all items. Perhaps you meant 'mimic' in a different way?
I am rebuilding the items every time from the original data collection, so perhaps instead of filtering my data collection and then rebuild the items, I can filter the items that were previously built; should speed it up a bit.
Dogs, as for the DataViewGrid, I pondered the idea in the past. I believe the reason I left it behind, was because of a few issues:
- I don't want to be forced to use grid lines.
- Each individual listview item has its own background and foreground color.
- A few others; can't really remember anymore.
So, I decided to go with the listview control; which gave me the best options ( I thought so, anyways ).