Click here to Skip to main content
15,916,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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);
        }
Posted
Updated 21-Jun-11 0:05am
v2

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;
}


Ofcourse you will need to test the values and see where you need to add the AND operators to construct a nice filter string
 
Share this answer
 
Comments
shonezi 21-Jun-11 6:26am    
works!!!!!!!!!!! THANKS A LOT MATE!!!!!!!!!
Your best bet is a single function that creates filters using every textbox that has text in it. Every event should call it.
 
Share this answer
 
Comments
shonezi 21-Jun-11 6:06am    
ok, how do I do that, I mean the code?

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