views:

130

answers:

3

I want to hide some items based on a text filter in a ListView (WinForms).
Basically the listview loads the items from a text file, and I don't want it to be read and/or written when the user searches the list. The search is done in a combobox's KeyDown event, but there is no "Visible" property of the ListViewItem.

Is there any easy way to do this, WITHOUT re-reading the file? (as it is an XML file, and it could even contain thousands of items, it would be hard to search efficiently and even let the user use the application, as the search would take for minutes (mostly with the loading)).

+1  A: 

It's not clear to me what you are trying to do. I'll still shout out a few ideas, maybe something is helpful...

  • Cache the file in memory
  • Cache the read items and fill the input box on the fly
  • Add and remove the items accordingly
  • Have a look at this question
  • Maybe it's impossible after all?

Sorry if I got you wrong. :(

mafutrct
I want to modify the Visible property on the fly... Or I would like to, as it does not exist... for me at least!
fonix232
The basic solution would be to add and remove the items, I guess.
mafutrct
Yes I know it would be, but as I pointed it out, making a simple database would not be so easy, as we are talking about thousands of items... I think I will continue googling around for a personalized ListViewItem class with Visible property... Or should I change to DataGridView? Does it even support automatic checkboxes?
fonix232
I don't see why you can't just store the items in, for instance, a list? Add and remove items from the ListView to/from this backup list. No need to parse the source file more than once.
mafutrct
Yes, maybe it is a good idea... but still requires more memory.The Visible property would make it much easier :D
fonix232
Yes, but even 10k items of 1k bytes each are only 10 megs of RAM - that's nothing, usually.
mafutrct
+1  A: 

You may be experiencing delay due to redrawing of listbox every add/remove operation. Try wrapping your Add/Remove op inside Begin/End Update method like this.

myListView.BeginUpdate();
//Add or Remove Items
myListView.EndUpdate();

Now feel the speed.

Ofcourse you have to load your file only once.

Veer
A: 

Resolved with creating a separate class for storing data, and searching it after loading the file.

Although writing changes to the file is still a question, but that's another story...

fonix232