Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted

1 solution

The following procedure can be used.
C#
//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;
 
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