title: DataGridView validating old value insted of new value
body: <p>I have a DataGridView that is bound to a DataTable, it has a column that is a double and the values need to be between 0 and 1. Here is my code</p>
  
  <pre><code>private void dgvImpRDP_InfinityRDPLogin_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
  {
      if (e.ColumnIndex == dtxtPercentageOfUsersAllowed.Index)
      {
          double percentage;
          if(dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value.GetType() == typeof(double))
              percentage = (double)dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value;
          else if (!double.TryParse(dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value.ToString(), out percentage))
          {
              e.Cancel = true;
              dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].ErrorText = "The value must be between 0 and 1";
              return;
          }
          if (percentage &lt; 0 || percentage &gt; 1)
          {
              e.Cancel = true;
              dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].ErrorText = "The value must be between 0 and 1";
          }
      }
  }
  </code></pre>
  
  <p>However my issue when <code>dgvImpRDP_InfinityRDPLogin_CellValidating</code> fires <code>dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value</code> will contain the old value before the edit, not the new value.</p>
  
  <p>For example lets say the old value was .1 and I enter 3. The above code runs when you exit the cell and <code>dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value</code> will be <b>.1</b> for that run, the code validates and writes <b>3</b> the data to the DataTable.</p>
  
  <p>I click on it a second time, try to leave, and this time it behaves like it should, it raises the error icon for the cell and prevents me from leaving. I try to enter the correct value (say .7) but the the <code>Value</code> will still be 3 and there is now no way out of the cell because it is locked due to the error and my validation code will never push the new value.</p>
  
  <p>Any recommendations would be greatly appreciated.</p>
  
  <p>EDIT -- 
  New version of the code based off of Stuart's suggestion and mimicking the style the MSDN article uses. Still behaves the same.</p>
  
  <pre><code>private void dgvImpRDP_InfinityRDPLogin_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
  {
      if (e.ColumnIndex == dtxtPercentageOfUsersAllowed.Index)
      {
          dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].ErrorText = String.Empty;
          double percentage;
          if (!double.TryParse(dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].FormattedValue.ToString(), out percentage) || percentage &lt; 0 || percentage &gt; 1)
          {
              e.Cancel = true;
              dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].ErrorText = "The value must be between 0 and 1";
              return;
          }
      }
  }
  </code></pre>