private void OnCellValidating(object source, DataGridViewCellValidatingEventArgs e) { var row = Grid.Rows[e.RowIndex]; if (row.IsNewRow) { return; } var validationProxy = new GridValidationIntegrationProxy(Grid.Columns[e.ColumnIndex].DataPropertyName, e.FormattedValue, this); ValidationIntegrationHelper helper; try { helper = new ValidationIntegrationHelper(validationProxy); } catch (InvalidOperationException) { // ignore missing property return; } var validator = helper.GetValidator(); if (validator == null) { // this property should not be checked return; } var validationResults = validator.Validate(validationProxy); if (!validationResults.IsValid) { var builder = new StringBuilder(); foreach (ValidationResult result in validationResults) { builder.AppendLine(result.Message); } row.Cells[e.ColumnIndex].ErrorText = builder.ToString(); } else { row.Cells[e.ColumnIndex].ErrorText = string.Empty; } }
private void OnCellValidating(object source, DataGridViewCellValidatingEventArgs e) { var row = Grid.Rows[e.RowIndex]; if (row.IsNewRow) { return; } var validationProxy = new GridValidationIntegrationProxy(Grid.Columns[e.ColumnIndex].DataPropertyName, e.FormattedValue, this); ValidationIntegrationHelper helper; try { helper = new ValidationIntegrationHelper(validationProxy); } catch (InvalidOperationException) { // ignore missing property return; } var validator = helper.GetValidator(); if(validator == null) { // this property should not be checked return; } var validationResults = validator.Validate(validationProxy); if (!validationResults.IsValid) { var builder = new StringBuilder(); foreach (ValidationResult result in validationResults) { builder.AppendLine(result.Message); } row.Cells[e.ColumnIndex].ErrorText = builder.ToString(); } else { row.Cells[e.ColumnIndex].ErrorText = string.Empty; } }