I still have the problem above. Let me try this from a different angle.
My application is WinForms and I am displaying a single Employee entity on a form (no grid). SelfServicing .Net 2.0.
Below I have provided code for ValidateFieldValue(). I have to validate that each Employee has a unique EmployeeCode. So in the validation code I create a new EmployeeEntity with the proposed EmployeeCode and I check if the returned entity has Fetched fields, in which case I have a duplicate. What I want to see is my error message displayed right beside the EmployeeCode TextBox on my form (it is really a Infragistics UltraTextEditor).
When I run this code and key in a duplicate EmployeeCode and tab out of the EmployeeCode field I definitely see the validation code execute in the debugger and the SetEntityFieldError statement is executed. However on the form I don't see any error message and all that happens is that I am positioned to the next field on the form.
I think that my validation code is in line with the documented examples so my question is what else do I have to do to get this to work? Do I need an ErrorProvider Control on my Form (I have tried with and without), do I need to include some logic on my Form.
Hopefully this clarifies my problem.
Thanks
public override bool ValidateFieldValue(IEntityCore involvedEntity, int fieldIndex, object value)
{
bool isValid = true;
string errorMessage = string.Empty;
EmployeeEntity entity = involvedEntity as EmployeeEntity;
involvedEntity.SetEntityFieldError(entity.Fields[fieldIndex].Name, string.Empty, false);
switch ((EmployeeFieldIndex)fieldIndex)
{
case EmployeeFieldIndex.Code:
if (entity.IsNew)
{
// Check that EmployeeEntity.Code is not a Duplicate
EmployeeEntity e = new EmployeeEntity(value.ToString());
if (e.Fields.State == EntityState.Fetched)
{
errorMessage = "Duplicate employee code";
entity.SetEntityFieldError(EmployeeFields.Code.Name, errorMessage, true);
isValid = false;
}
}
break;
default:
break;
}
return isValid;
}