title: Last RowHeader click on DataGridView
body: <p>In my C# windows forms program I would like to update the <code>TextBox</code>es according to the <code>RowHeader</code> clicked on in the <code>DataGridView</code>:</p>
  
  <pre><code>if (e.RowIndex != -1 || e.ColumnIndex != -1)
  {
      fnameBox.Text   = dgvPatient.Rows[rowIndex].Cells[0].Value.ToString();
      mnameBox.Text   = dgvPatient.Rows[rowIndex].Cells[1].Value.ToString();
      lnameBox.Text   = dgvPatient.Rows[rowIndex].Cells[2].Value.ToString();
      mobnumBox.Text  = dgvPatient.Rows[rowIndex].Cells[3].Value.ToString();
      emailBox.Text   = dgvPatient.Rows[rowIndex].Cells[4].Value.ToString();
      bdate.Value     = Convert.ToDateTime(dgvPatient.Rows[rowIndex].Cells[5].Value.ToString());
      medHistBox.Text = dgvPatient.Rows[rowIndex].Cells[6].Value.ToString();
  }
  </code></pre>
  
  <p>So, my problem is that the <code>DataGridView</code> shows an empty row at the end, so when I click on this header, the `Convert.ToDateTime statement throws an error and bugs the app. I tried checking if the result of conversion is null value... the code above is latest trial and it also failed.</p>
  
  <p>How do I remove the error of clicking on the last <code>RowHeader</code>?</p>