Hi,
I have a DataGridView with a table loaded onto it. I have nine textboxes which will serve as a search feature for the DataGridView. What I want is that once text is entered, it goes through the relevant column filtering data as per what is inputed. This works perfectly and have severally typed code that still worked well despite not being exactly same code. My problem arises from the fact that after filtering using one textbox, when I enter the text in another textbox in order to filter results I had, it instead discards the previous filter and searches as if it were the first time filtering data. Here is the code that fills a DataSet and DataView.
public void FillDataSet(string sql, DataSet dataSet, DataView dataView, string tableName)
{
try
{
using (OleDbConnection connection = new OleDbConnection(databaseConnString.GetConnectionString))
{
connection.Open();
using (OleDbDataAdapter adapter = new OleDbDataAdapter(sql, connection))
{
adapter.Fill(dataSet, tableName);
dataView.Table = dataSet.Tables[tableName];
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "An unexpected error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Here is the method that filters the DataView
public void FilterDataSet(DataView dataView, string FilterCriteria, DataGridView dataGridView)
{
DataTable tbl = new DataTable();
dataView.RowFilter = FilterCriteria;
dataGridView.DataSource = tbl;
}
Here is an instance that I call the method to filter - this works perfectly
private void tbPartNumber_TextChanged(object sender, EventArgs e)
{
filterPartNum = "PartNumber LIKE '%" + tbPartNumber.Text + "%'";
populator.FilterDataSet(tblPartsDataView, filterPartNum, partDetailsDataGridView);
}
I have attached a screenshot of my filter textboxes.
Please help me extend usability of this filter to be a multifilter,
Thanks in advance.