I'm testing out how I will handle validation in the UI. I've been reading previous posts about using the validator classes, but I'm still at a loss with this situation.
I've created a simple winforms user control to test validating entities. In the user control, I simply bind a few textboxes to a few properties on my entity.
// populate with a participant by pkid
ProductionParticipantsEntity participant = new ProductionParticipantsEntity(pkid);
tbFirstName.DataBindings.Add("Text", participant, "FirstName");
tbLastName.DataBindings.Add("Text", participant, "LastName");
tbEmail.DataBindings.Add("Text", participant , "Email");
Now, I somewhat understand how to use the validator classes to apply business logic to the validation routine, but what I cant find is how to intercept the very first level of validation which is checking if the changed value will fit in the database field. An example is if I try to put too many characters into the tbFirstName textbox. What happens when I try to tab or click out of the textbox that now contains too many characters for its underlying database field, focus will not leave the textbox because the value is too large for the field. This wont be very intuitive to my users.
When I stepped through the code, it seems like an excpetion is thrown from the support classes object EntityBase. So naturally one approach could be to ovverride the setNewValue method in the ProductionParticipantEntity class and do something there with it. Problem with that approach is..
- I would like to keep that logic that tells the user about the problem out of the Entity classes as I consider this a UI function.
- I dont want to have to add that code to every single entity object I have. I realize generating this ovverride might work, but then I would have to know how to handle this situation with the user.
- I dont know how to know in the user control that this part of validation has failed.
Ulitmately what I am trying to do is create a generic form or usercontrol that when hooked up to an entity object, provides all the fields for edit/add as well as provides the ui logic to tell the user when they've entered invalid data.
Anyone trying to do something similar that might want to collaborate on this effort, or at least offer some ideas on how to solve this problem?
Thanks,
Jim