Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form with many controls such as textbox, combobox, checkbox and etc.
User can fill them or let them empty and then press Filter button.
What are the solutions, is it possible to do it with LINQ?
Thanks
Posted

It is possible to use LINQ in principle, but hardly makes much sense. Controls are organized in parent-child relationships in one single hierarchy, so you will need to search it recursively using the property System.Windows.Forms.Control.Controls. This is simple, but what's your search criteria?

I would note though that the necessity of such search is a good sign of really bad UI design. Correct design never needs such search.

The basic idea is: you need to have a data layer isolated from UI; you will need data binding or population of of the UI with the data, update of the data based on UI. (A hint: think "Controller".)

I suggest you learn and analyze applicability of the following architectural patterns (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):

MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

—SA
 
Share this answer
 
Comments
Mehdi Gholam 16-Nov-11 3:55am    
Expertly said, 5!
Sergey Alexandrovich Kryukov 16-Nov-11 3:58am    
Thank you, Mehdi. After all they call us experts, should we be adequate to it or not? :-)
--SA
Hamid Noahdi 16-Nov-11 4:00am    
Thanks for answer, what you say about architectural patternsis completely right, but i need a solution for advanced filter, for example sometimes user need to filter a persons name, sometimes name and family or many other options like sex, age, born date and etc.
Yes it is very much possible using LINQ, and simple too!!! :)

follow the link to learn in detail.

http://blogs.msdn.com/b/vbteam/archive/2007/08/29/implementing-dynamic-searching-using-linq.aspx[^]

http://weblogs.asp.net/rajbk/archive/2007/09/18/dynamic-string-based-queries-in-linq.aspx[^]

http://equivalence.co.uk/archives/819[^]

mark as answer if solves your problem, it motivates :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900