Suggestions for implementing a simple search for “business objects” in a .NET WinForms app?

前端 未结 4 484
失恋的感觉
失恋的感觉 2021-01-16 03:01

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

4条回答
  •  日久生厌
    2021-01-16 03:42

    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:

    1. Use the double click speed to calculate an appropriate delay before performing the search.
    2. Provide a callback mechanism to perform the search instead of building it into the control. Perhaps something like an IFilterable interface?

提交回复
热议问题