title: Set focus to Data Grid View Text Box Column Cell
body: <p>I have a gridview of type datagridview text box column, in that following columns are there:</p>
  
  <pre><code>SrNo    | Description    | HSNCode    | Qty   | Rate   | Amount
  </code></pre>
  
  <p>I am generating amount in my program automatically, but I want to check if the user has entered to amount field without entering data in "Rate" then I want to set focus back to the "Rate" field in my program:</p>
  
  <p>I have tried following code:</p>
  
  <pre><code>private void grdData_CellLeave(object sender, DataGridViewCellEventArgs e)
  {
     if (e.ColumnIndex == 4)
     {
         if(grdData.Rows[e.RowIndex].Cells[4].Value== null)
         {
             grdData.CurrentCell = grdData.Rows[e.RowIndex].Cells[4];
         }
      }
  }
  </code></pre>
  
  <p>But the code is not working.<br>
  What should I do to switch focus to the field that is previous to the "Amount"?<br>
  Please help.</p>