Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When run, the database has not changed- nothing happens when I add text to the textbox to search with
private void textBox5_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        if (String.IsNullOrEmpty(textBox5.Text))
            customer_OrdersBindingSource.Filter = string.Empty;
        else
            customer_OrdersBindingSource.Filter = string.Format("{0}='{1}'", comboBox1.Text, textBox5.Text);
    }
}


What I have tried:

private void textBox5_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        if (String.IsNullOrEmpty(textBox5.Text))
            customer_OrdersBindingSource.Filter = string.Empty;
        else
            customer_OrdersBindingSource.Filter = string.Format("{0}='{1}'", comboBox1.Text, textBox5.Text);
    }
}
Posted
Updated 24-Apr-18 17:05pm
v2

1 solution

One obvious question is, how does the expression look like when it's added into the filter. using debugger, place a breakpoint on the line where you set the filter and ensure that the filter has proper value. For example is the text in combobox written exactly the same way how the column is named in the data source

When clearing the filter, instead of setting an empty string to the filter, it's recommended to use BindingSource.RemoveFilter Method (System.Windows.Forms)[^]

I take it that the idea is to allow user to search with partial text, in other words the text does not need to match the value in the data source in whole. If this is the case you probably should change the equality comparison to LIKE. In other words something like
C#
customer_OrdersBindingSource.Filter = string.Format("{0} LIKE '{1}*'", comboBox1.Text, textBox5.Text);
For more information, see DataColumn.Expression Property (System.Data)[^]
 
Share this answer
 

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