title: How to validate a datagridview column with 3 database field combine together
body: <p>Basically I have a datagridview which I retrieve from database and 3 of the database field column I combine into a column in datagridview.</p>
  
  <p>But now the problem come, I need to do update but before that I need to validate what the user have editing before click on the update button, but I don't know how to validate them when they are in the same column in the datagridview.</p>
  
  <p>I am able to validate a column with only one database field</p>
  
  <p>p.s I am doing editing and updating in the datagridview, I need to validate that 3 database field column.</p>
  
  <p>This is how I call my databasase into the datagridview</p>
  
  <p>ps. the position is int</p>
  
  <pre><code>protected void BindStaff()
  {
    SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=BRandCom;Integrated Security=True");
    SqlDataAdapter adapter = new SqlDataAdapter("SELECT StaffID, (StaffName+','+ StaffNRIC+','+ Position + ';')as StaffDetail, yearIn, age, address, email, stayIndicator FROM StaffBook", conn);
    DataSet ds = new DataSet();
    adapter.Fill(ds);
    DGVStaffBook.DataSource = ds.Tables[0];
  }
  </code></pre>
  
  <p>this is the column i am saying i am able to validate (only one database field column)</p>
  
  <pre><code>private void DGVStaffBook_CellEndEdit(object sender, DataGridViewCellEventArgs e)
      {
        if (e.RowIndex &gt;= 0 &amp;&amp; e.ColumnIndex &gt;= 0)
        {
  
          int stayInd;
  
         if (e.ColumnIndex == 6)
          {
            stayInd = Convert.ToInt32(DGVStaffBook.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
  
            if (stayInd != 0 &amp;&amp; stayInd != 1)
            {
              MessageBox.Show("Please enter only 1 or 0");
              DGVStaffBook.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = DBNull.Value;
            }
            else
              return;
  
          }
        }
  
      }
  </code></pre>
  
  <p>i try this for position , but it give me error: input string was not correct format</p>
  
  <pre><code>  private void DGVStaffBook_CellEndEdit(object sender, DataGridViewCellEventArgs e)
          {
              if (e.RowIndex &gt;= 0 &amp;&amp; e.ColumnIndex &gt;= 0)
              {
  
                               if (e.ColumnIndex == 1)
                  {
                      String[] position = null;
                      position = Convert.ToString(DGVStaffBook.CurrentRow.Cells[1].Value).Split(',');
  
                      if (int.Parse(position[2]) != 1 &amp;&amp; int.Parse(position[2])!=2 ) 
                      {
                          MessageBox.Show("Please Update number type accordingly:" + Environment.NewLine + "1  - High rank only " + Environment.NewLine + "2  -Low Rank" );
                      }
                      else 
                          return;
  
                  }
              }
  
          }
  </code></pre>