Click here to Skip to main content
15,748,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my form,

I have Textbox1(with label1 [From size]) and Textbox2(with label2 [To size.

I have a button(search button).

I have a dataGridView1 which includes binding source from one table form the local database. and one of the columns in the dgv is size column.

My question is:

if I enter the from size (ex: 3.2 inch) in textbox1 and To size (ex: 3.5 inch) in textbox2 and press on search button how can I get the rows the have this size range in the dataGridView ???

I did this to filter the dgv by datetimepickers

private void pictureBox10_Click(object sender, EventArgs e) 
        string From = Convert.ToDateTime(dateTimePicker1.Value).ToString("yyyy-MM-dd HH:mm:ss.ff");
        string To = Convert.ToDateTime(dateTimePicker2.Value).ToString("yyyy-MM-dd HH:mm:ss.ff");
        table1BindingSource.Filter = string.Format("([{0}] >= #{1}# AND [{0}] <= #{2}#)", "Date", From, To);
Maciej Los 24-Oct-15 15:05pm    
What database?
What kind of object is bind with dgv?

1 solution

Something like this should work. Very similar to your existing code.
The exact syntax of the filter might have to be changed.
private void buttonSearch_Click(object sender, EventArgs e)
    table1BindingSource.Filter = string.Format("([{0}] >= {1} AND [{0}] <= {2})", "Size", Textbox1.Text, Textbox2.Text);

For help with the syntax see DataColumn.Expression Property[^]
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