How to filter datagridview using a textbox in C#?

Viewed 27569

I tired to filter a datagridview using a textbox, the textbox is contained in a tabpage, but it is not working, here is the code :

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        try
        {
            ((DataTable)dataGridView1.DataSource).DefaultView.RowFilter = "like '%" + textBox1.Text.Trim() + "%' ";
        }
        catch (Exception) { }

    }
2 Answers
Related