如何使用C#使用ComboBox过滤DataGridView [英] how to filter the DataGridView using ComboBox using C#

查看:257
本文介绍了如何使用C#使用ComboBox过滤DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表格中,



我有Textbox1(带有label1 [来自大小])和Textbox2(带有label2 [To size。



我有一个按钮(搜索按钮)。



我有一个dataGridView1,它包含来自本地数据库的一个表的绑定源。 dgv中的一列是size列。



我的问题是:



如果我在textbox1中输入from size(ex:3.2英寸),在textbox2中输入To size(ex:3.5英寸)并按下搜索按钮如何在dataGridView中获取具有此大小范围的行???



我这样做是为了通过datetimepickers过滤dgv



  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}#) 日期,From,To);
}

解决方案

 table1BindingSource.Filter =  string  .Format( ({0} BETWEEN {1} AND {2})  ColumnName,Convert.Todouble(txtbox1.Text),Convert.Todouble(txtbox2。文本)); 


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);
    }

解决方案

table1BindingSource.Filter =  string.Format("({0} BETWEEN {1} AND {2})","ColumnName", Convert.Todouble(txtbox1.Text),Convert.Todouble(txtbox2.text));


这篇关于如何使用C#使用ComboBox过滤DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆