Click here to Skip to main content
15,898,938 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
private void button1_Click(object sender, EventArgs e)
        {

            if (ch1.Checked && ch2.Checked && ch3.Checked)
            {
                string filter = string.Format("ACCentrala = \'" + (centrala.Text + "\'"));
                filter += " AND ";
                filter += string.Format("ACTelefon = \'" + (lokal.Text + "\'"));
                filter += " AND ";
                filter += string.Format("ACPloca = \'" + (ploca.Text + "\'"));
                this.istorijaBS.Filter = filter;
            }
        }


I need help with code above, I have three textboxes text1, text2 and text3, 3 checkboxes check1, check2 and check3. when check1 is checked text1 is active filter...and so on. but in this code when I check all 3 of them for filtering with all 3 textboxes it doesnt work?
Posted
Updated 24-Jun-11 10:12am
v3

1 solution

C#
string filter1 = string.Format("ACCentrala = \"{0}\"", centrala.Text);
string filter2 = string.Format("ACTelefon = \"{0}\"", lokal.Text);
string filter3 = string.Format("ACPloca = \"{0}\"", ploca.Text);

string filter = "";

if (ch1.Checked)
{
    filter = filter1;
}
if (ch2.Checked)
{
    if (!string.IsNullOrEmpty(filter))
    {
        filter += " AND ";
    }
    filter += filter2;
}
if (ch3.Checked)
{
    if (!string.IsNullOrEmpty(filter))
    {
        filter += " AND ";
    }
    filter += filter3;
}
this.istorijaBS.Filter = filter;
 
Share this answer
 
v3
Comments
shonezi 24-Jun-11 16:06pm    
it says it cant intepret token on position 14 and 26????
[no name] 24-Jun-11 16:41pm    
Try again now - a couple of close brackets were missing.
shonezi 25-Jun-11 10:09am    
I did put the brackets, I saw it but still the same message
shonezi 27-Jun-11 6:24am    
my bad , it works with loaded binding source, not the one I made myself. THANKS!!!!

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