title: C# Visual - Datagridview search if textbox = cell string
body: <p>I am trying to make it so that when you enter data into <code>DataGridView</code> it first checks
  if the ID textbox contains a string that exists in the <code>DataGridView</code> ID column and throws an error if it finds a match.</p>
  
  <p>If it does not match then the system can add the data.</p>
  
  <p>I tried all kind of codes that people posted nothing worked.
  here is my latest.</p>
  
  <pre><code>private void btnadd_Click(object sender, EventArgs e)
  {
      Label label25 = new Label();
  
      foreach (DataGridViewRow row in dataGridView1.Rows)
      {
          if (row.Cells[0].Value.ToString() == IDtxtbox.Text)
          {
              label25.Text = "ID was already created,try some other number";
              break;
          }
          else
          {
              dataGridView1.Rows.Add(IDtxtbox.Text, Nametxtbox.Text);
              break;
          }
      }
  }
  </code></pre>