在多个过滤器上需要帮助 [英] need help on multiple filters

查看:76
本文介绍了在多个过滤器上需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datagridview,8个文本框和一个按钮,datagrid充满了dataadapter,文本框用作过滤器,当它们一个接一个地使用时它们可以正常工作,但是我想将它们组合起来,只有8个它们,并且有很多组合,我该如何克服这个问题,这是我用来一一过滤的代码

I have a datagridview, 8 textboxes, and a button, datagrid is filled with dataadapter, textboxes are used as filters, and they work fine when used one by one, but I want to combine them, only thing there is 8 of them, and there is a lot of combinations, how can I overcome this, here is the code I use for filtering one by one

private void ACpodaci_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'tMNcentarDataSet.ACpodaci' table. You can move, or remove it, as needed.
            this.aCpodaciTableAdapter.Fill(this.tMNcentarDataSet.ACpodaci);
            
        }
        private void centrala_TextChanged(object sender, EventArgs e)
        {
            this.aCpodaciBindingSource.Filter = string.Format("ACCentrala LIKE \'{0}%\'", this.centrala.Text);
        }
        private void lokal_TextChanged(object sender, EventArgs e)
        {
            this.aCpodaciBindingSource.Filter = string.Format("ACLokalUKorporativnojMrezi LIKE \'{0}%\'", this.lokal.Text);
        }
        private void klasa_TextChanged(object sender, EventArgs e)
        {
            this.aCpodaciBindingSource.Filter = string.Format("ACKlasa LIKE \'{0}%\'", this.klasa.Text);
        }
        private void tip_TextChanged(object sender, EventArgs e)
        {
            this.aCpodaciBindingSource.Filter = string.Format("ACTipAparata LIKE \'{0}%\'", this.klasa.Text);
        }
        private void shelf_TextChanged(object sender, EventArgs e)
        {
            this.aCpodaciBindingSource.Filter = string.Format("ACShelf LIKE \'{0}%\'", this.shelf.Text);
        }
        private void ploca_TextChanged(object sender, EventArgs e)
        {
            this.aCpodaciBindingSource.Filter = string.Format("ACPloca LIKE \'{0}%\'", this.ploca.Text);
        }
        private void direkcija_TextChanged(object sender, EventArgs e)
        {
            this.aCpodaciBindingSource.Filter = string.Format("ACDirekcija LIKE \'{0}%\'", this.direkcija.Text);
        }
        private void stanje_TextChanged(object sender, EventArgs e)
        {
            this.aCpodaciBindingSource.Filter = string.Format("ACStanje LIKE \'{0}%\'", this.stanje.Text);
        }

推荐答案

不能使用函数来计算过滤器,例如:

Can''t you use a function to calculate the filter like:

private void filterAll()
{
string filter = string.Format("ACCentrala LIKE \''{0}%\''", this.centrala.Text);
filter += " AND ";
filter += string.Format("ACLokalUKorporativnojMrezi LIKE \''{0}%\''", this.lokal.Text);
.
.
.
this.aCpodaciBindingSource.Filter = filter;
}



当然,您将需要测试这些值,并查看需要在何处添加AND运算符以构造一个不错的过滤器字符串



Ofcourse you will need to test the values and see where you need to add the AND operators to construct a nice filter string


您最好的选择是一个单个函数,该函数使用每个具有里面的文字.每个事件都应该调用它.
Your best bet is a single function that creates filters using every textbox that has text in it. Every event should call it.


这篇关于在多个过滤器上需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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