问题描述
在我的表格中,
我有Textbox1(带有label1 [来自大小])和Textbox2(带有label2 [To size。
我有一个按钮(搜索按钮)。
我有一个dataGridView1,它包含来自本地数据库的一个表的绑定源。 dgv中的一列是size列。
我的问题是:
如果我在textbox1中输入from size(ex:3.2英寸),在textbox2中输入To size(ex:3.5英寸)并按下搜索按钮如何在dataGridView中获取具有此大小范围的行???
我这样做是为了通过datetimepickers过滤dgv
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);
}
推荐答案
private void buttonSearch_Click(object sender, EventArgs e)
{
table1BindingSource.Filter = string.Format("([{0}] >= {1} AND [{0}] <= {2})", "Size", Textbox1.Text, Textbox2.Text);
}
有关语法的帮助,请参阅 []
这篇关于如何使用C#通过两个文本框过滤DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!