Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

If I’m using the MVVM pattern – this one for my WPF application

And my project requires a search function on different sources – say clients, accountants, cases.

What would be the best way to go about it so that I only have one search view and the search results shown in the ListView are ‘dynamic’ in that they could be result for clients or accountants or cases

Should I have a base search view model and specific view models for clients, accountants, cases that then somehow set as the datacontext for the search view

Or

try to build the grid dynamically in a code behind for the search and then somehow get the data back into the view model without the search view knowing about the view model.

For clarification

The searches are separate and will not need to be combined, I would only every return results for clients or accountants or cases.

share|improve this question

2 Answers 2

Map a generic View Model to whatever you are searching on. The field names in the View Model will always be the same, i.e. ID, Title, Description or something like that.

For example, if you are searching for clients, map ID in your ViewModel to ClientID in your model, Title to ClientName, and Description to ClientProfile.

If you need to display different entities in the same search (e.g. clients and cases together), you will need to do multiple searches and UNION the results, or maintain a denormalized table of search descriptions.

share|improve this answer
    
added clarification to question –  Rob Jul 13 '11 at 15:29

I would build a grid for each search type case. e.g.

SEARCH RESULTS

Accounting

result 1 result 2 result 3

Cases

result 1 result 2 result 3

etc.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.