'how to filter rows using Query typed DataSets to show specific rows based on column value (User input) and search box(user input)?

I have a database table with the next columns.

[productId] [ArticleNo][Manufacturer][ProductName][ProductDetails][RealStoc][MinimumStoc][MeasurementUnit][Location]

I fill datagridview using Datasources.

I have Two textBoxes ( textBox1 ; textBoxLocationSearch;)

This is my code:

      private void textBox1_TextChanged(object sender, EventArgs e)
    {
        string locationValue = textBoxLocationSearch.Text.ToString();
        string searchValue = textBox1.Text.ToString();
        int rowIndex = -1;

        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
            try
            {
                if (row.Cells[4].Value.ToString().Equals(searchValue) && row.Cells[8].Value.ToString().Equals(locationValue))
                {
                    rowIndex = row.Index;
                    break;
                }

               
            }
            catch (Exception exc)
            {

                MessageBox.Show(exc.Message);
            }
           
        }
    }
}

I want to display in datagridview only the rows that contains specific words inserted by user into textbox1.Text and with the specific cell value and cell index inserted into textBoxLocationSearch.Text.

I mean, i want to get all the rows that contains: apple in the A3 location. It's a location search filter...

I managed to get all rows by user input, and all rows by location input. but never together..

What i want



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source