BindingSource.Filter:组合多个过滤器 C# Winforms [英] BindingSource.Filter: Combining Multiple Filters C# Winforms

查看:23
本文介绍了BindingSource.Filter:组合多个过滤器 C# Winforms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个连接到 Access 数据库的程序.我有 3 个搜索条件正在尝试组合.其中两个过滤器来自复选框,而第三个是搜索框.单独使用这 3 个效果很好.但是,当尝试连接过滤器时,它似乎只能识别CheckedSListFilter".我已经测试了连接字符串的多次迭代,但没有任何运气.我希望这只是一个语法问题.谢谢你的帮助.

I am writing a program that hooks into an Access Database. I have 3 search criteria I am attempting to combine. Two of the filters are derived from checkboxes, while the 3rd is a searchbox. Individually these 3 work great. However, when attempting to Concatenate the filters it seems to only recognize the 'CheckedSListFilter'. I have tested multiple iterations of the concatenated string without any luck. I'm hoping this is just a syntax issue. Thanks for your help.

        string SFilter = CheckedSListFilter();// method returns string "S = 'w1' OR S = 'w2' OR S = 'w3'"
        string PFilter = CheckedPStatusFilter();//method returns string "PA = 'True' OR "PB = 'True'"
        string CFilter = comboBox_SearchFields.Text;
        string filter = CFilter + " LIKE '" + "*" + textBox_search.Text + "*" + "'";//returns "R LIKE '*g*'"

                BindingSource bs = this.projectBindingSource;
                bs.Filter =  filter+" AND "+"("+PFilter +" OR "+SFilter+")";

推荐答案

我自己解决了这个问题.操作顺序让我绊倒了.最终做了这样的事情: bs.Filter = "("+SFilter+")"+" AND "+"("+PFilter+")"+" AND "+"("+PFilter+")";现在一切都按预期工作.

Solved this on my own. Order of operations was tripping me up. Ended up doing something like this: bs.Filter = "("+SFilter+")"+" AND "+"("+PFilter+")"+" AND "+"("+PFilter+")"; All now works as expected.

这篇关于BindingSource.Filter:组合多个过滤器 C# Winforms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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