本文介绍了应用多次过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我一直在寻找一种使用文本框应用多次过滤并在数据网格视图中显示结果的解决方案.此数据是从SQL Server导入的,并被p打印到datagridview.
谢谢与问候
Aryan Kukreja
Hey Guys,
I''ve been looking for a solution to apply multiple filtration using text boxes and showing the result in Data grid view. This data is imported form SQL Server and p-printed to datagridview.
Thanks and Regards
Aryan Kukreja
推荐答案
//Create a binding source
BindingSource bindingSource1 = new BindingSource();
//Set the datasource property of bindingsource to the DataSet
bindingSource1.DataSource = NorthWindDataset1;
//Set the DataMember property to the required DataTable
bindingSource1.DataMember="Customers";
//Set the DataSource property of DataGridView to the BindingSource
dataGridView1.DataSource = bindingSource1;
//Create a button and in the Click event of button insert the following code
//Now to apply multiple filter, create a filter string based on the data of the text boxes
string filterString = string.Format("CustomerID='{0}' and City='{1}' and Region='{2}",textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim());
//set the filter of bindingSource1
bindingSource1.Filter=filterString;
这篇关于应用多次过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!