Filtering a listview

Lanc1988

Contributor
Joined
Nov 27, 2003
Messages
508
I have a listview and its property is set to details view. It has 200+ items in it and 4 columns (Name, Level, Hits, Type).

I entered all the items in the control, it doesn't load them from a file.

I also have a textbox and a button, in the textbox I want to user to be able to type all or part of the name of the item they want and it will remove all items that do not match.
 
I would start by taking everything out of the listview and putting it in an external data structure of some kind. You should be able to iterate through the listview's items and organize put them into something like a list view. Make a class that has four data members (name, level, hits, type), make a new object of that type for each row in the listview and put it in the list. (maybe even write it out to a file and the ability to read it back in again...my god man, the humanity...all by hand..?..phew..)

When the user enters something into the textbox and clicks the button, you will go through your new data structure, find things that don't meet the criteria they entered (get filtered out) and add them as a list viewitem to the listview. When they do a new search, clear the listview and do it over again.

It may be kind of slow and flickery, so any kind of good organization of data would be a must (though there may not be any way around that).
 
Or you could just use a pre-built, totally awesome control.

That's a sweet control...at least the demo is cool. Looks like your lucky day. Someone's already done all the hard work..
 
Back
Top