title: Search for value in DataGridView in a column
body: <p>I want the user to be able to search for a number in a column in the DataGridView (dgv). The dgv can hold many records. Each record has a Project Number. So I want the user to be able to search for a project number in column Project Number. The columns I have are: ProjectID(not visible); Image(no headertext); Project Number; Project Name; Company; Contact.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>private void btnSearch_Click(object sender, EventArgs e)
  {
      string searchValue = textBox1.Text;
      int rowIndex = -1;
  
      dgvProjects.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
      try
      {
          foreach (DataGridViewRow row in dgvProjects.Rows)
          {
              if (row.Cells[row.Index].Value.ToString().Equals(searchValue))
              {
                  rowIndex = row.Index;
                  dgvProjects.Rows[row.Index].Selected = true;
                  break;
              }
          }
      }
      catch (Exception exc)
      {
          MessageBox.Show(exc.Message);
      }
  }
  </code></pre>
  
  <p><strong>Problem #1:</strong> What it does so far: The user types the project number in TextBox1. When he/she clicks the button, the code searches for this string in the rows, and when found the project number, that row gets selected. It works fine, but only once. When I want to search for an other project number, nothing happens.</p>
  
  <p><strong>Problem #2:</strong> I think this can be done in a better way, by searching the values for column Project Name only. But how should I do this properly?</p>
  
  <p>The code I used to search comes from <a href="https://stackoverflow.com/q/10179223/1671161" title="this answer">this answer</a></p>