What\'s the best way to go about providing a simple search capability for \"business objects\" in a .NET WinForms application?
By \"simple search\" I mean something
I don't know about the "best" way (I'd work at Google if I did). Given that, though, I did implement something similar in a proof-of-concept/customer demo a few months back that did the trick. Note that I was able to constrain the problem domain pretty effectively, especially wrt the immediately searchable dataset's size, so that performance wasn't an issue.
I created a FilterableListView
UserControl. I used a ListView in Detail mode, I dropped a TextBox immediately above it and used platform interop to give it some CueText (something like "Filter" or "Search"). I then updated the contents of the ListView
from a background thread (using the equivalent of my implementation of SafeInvoke) if there was a 0.5 second delay since the last TextChanged event from the filter box.
I did a simple, case-insensitive substring match against the contents of a specified field in the ListView
, it was quick, simple, and effective. I found Linq to Objects to be very useful.
A few things I would have done better for a more production-ready implementation:
IFilterable
interface?