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; }}