Winforms中的动态高级搜索 [英] Dynamic advanced search in winforms

查看:91
本文介绍了Winforms中的动态高级搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有许多控件的表单,例如文本框,组合框,复选框等.
用户可以填充它们或让它们为空,然后按筛选器"按钮.
有什么解决方案,可以用LINQ做到吗?
谢谢

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

推荐答案

原则上可以使用LINQ,但意义不大.控件按父子关系组织在一个单独的层次结构中,因此您将需要使用属性System.Windows.Forms.Control.Controls进行递归搜索.这很简单,但是您的搜索条件是什么?

我要指出的是,这种搜索的必要性是真正糟糕的UI设计的一个好兆头.正确的设计永远不需要这种搜索.

基本思想是:您需要使数据层与UI隔离;您将需要数据绑定或使用数据填充UI,并需要基于UI更新数据. (提示:请考虑控制器".)

我建议您学习并分析以下建筑模式的适用性( http://en.wikipedia .org/wiki/Architectural_pattern_(computer_science) [^ ]):

MVVM —模型视图视图模型,
http://en.wikipedia.org/wiki/Model_View_ViewModel [> http://en.wikipedia.org/wiki/Model-view-controller [ ^ ])),

MVA —模型视图适配器,
http://en.wikipedia.org/wiki/Model–view–adapter [ ^ ],

MVP —模型视图呈现器,
> http://en.wikipedia.org/wiki/Model-view-presenter [ ^ ].
请注意这些架构的动机.如果您了解它,就可以提出更好的设计思路.

—SA
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


是的,使用LINQ很有可能,而且也很简单!!! :)

请点击链接以详细了解.

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 [
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 :)


这篇关于Winforms中的动态高级搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆