title: Checking if first column of datagridview contains a string
body: <p>Good day to all.</p>
  
  <p>I am writing a code to input ID numbers in a datagridview. Before adding it, the code should check first if the "Name" is already present in the datagridview. If it is, then it will not add it to the datagridview and will display a messagebox.</p>
  
  <p>Below is how the datagridview items looks like:</p>
  
  <pre><code>Name     | ID Number
  Thomas   | 10000000
  Cesar    | 10000001
  Kathrina | 10000002
  </code></pre>
  
  <p>Below is the code I am working on. String s1 and s2 is still being copied in the datagridview even I already have "Thomas" in the "Name" column.</p>
  
  <pre><code>string s1 = "Thomas";
  string s2 = "10000003";
  
  if (dataGridView1 != null)
  {
          foreach (DataGridViewRow item in dataGridView1.Rows)
          {
              if (item.Cells[0].Value != null &amp;&amp; item.Cells[0].Value.ToString() != s1)
              {
                  string newline = s1 + "," + s2;
                  string[] values = newline.Split(',');
  
                  this.dataGridView1.Rows.Add(values);
              }
              else
              {
                 MessageBox.Show("Name already exists in the database");
              }
           }
  }
  </code></pre>
  
  <p>Can I know what I am missing in my code? </p>
  
  <p>Thank you very much in advanced for the usual help.</p>