DataGridView problem using ErrorText Validation

Jun 26 2006 4:36 PM
I'm trying to setup cell validation for a DataGridView using the CellValidating event and the grid's ErrorText property.  Problem is, when the validation fails and I set the event's Cancel (true) and ErrorText (errormsg) properties, the validation Icon does not display in the cell.  It will only display if I set the Cancel property to false.

Also, when Cancel is true, focus can not change.  Even though the form's AutoValidate property is set to EnableAllowFocusChange.  Correcting the cell's value will allow focus to change.

Any ideas?  Thanks.

private void dgvConfigurations_OnCellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
   DataGridView grid = (DataGridView)sender;
   DataGridViewCell cell = grid.CurrentCell;

   // Perform cell level validation.
   if (cell.OwningColumn.Name == "Price")
   {
      if (!_calcWorksheet.IsValidWorksheetNumber(e.FormattedValue.ToString()))
      {
         cell.ErrorText = "Whole number between 0 and 100 is required";
         e.Cancel = true;
      }
      else
      {
         cell.ErrorText = string.Empty;
         e.Cancel = false;
      }
   }
   else
   {
      return;
   }
}