Visual Studio 2013 / Windows Form
Posted on 2015-01-16
I am new to Visual Studio and Windows Forms.
Im trying to filter a DataGridView by both an unbound ComboBox (cb_searchtype) that selects a column and a Textbox (tb_keywords) that selects keywords within that column.
The goal is that the dropdown has three entries matching column headers (unbound), and the Keywords textbox will select text from within the matching column. Im using the code below, but it fails with a syntax error:
private void searchclick(object sender, EventArgs e)
BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = "'%" + cb_SearchType.Text + "%' + like '%" + tb_keywords.Text + "%'";
dataGridView1.DataSource = bs;
Im trying to get the dropdown (cb_searchtype) to pass the Text value of the column header so that the value passed by tb_keywords will Select records. If I statically set the column name with [column] in the above code, it works fine for the keywords, but I need to pass the value of the dropdown to that filter.
The logic is "SELECT * FROM MyTable WHERE cb_searchtype = [dropdown value] AND tb_keywords = [keywords value]"
Thank you in advance.