I need to implement input validation throughout my winform app. There are many different forms where data can be entered and I would like to not go control by control by form and create isValid etc per item. How have others dealt with this?
I see that most related posts deal with Web Apps and/or mention Enterprise Library Validation Application Block. Now I admit I haven’t thoroughly researched ELVAB but it seems like overkill for what I need. My current thought is to write a class library with the various requirements and pass it a control as a parameter. I already have a Library of RegEx functions for things like isValidZipCode and such so that may be a place for me to start.
What I would like to have is a Validate button that onClick cycles through all the controls on that Form Page and performs the needed validation. How can I accomplish this?
In my own application I need to validate dimensions as they are typed in. The sequence I used is as follows
The advantage of this approach that validation is centralized in one location for a given Shape Program. I don’t have to go modify each control or even really worry about the different types of controls on the form. Way back when I designed the software I decided how the UI going to work for textboxes, listboxes, combo boxes, etc. Also different levels of severity is handled differently.
The View takes care of that instructing the Form what to do through the Interface. How it actually is implemented is handled by the Form itself in it’s implementation of the Interface. The View doesn’t care if the Form is displaying yellow for warning and red for error. Only that it handles those two levels. Later if a better idea of displaying warning vs errors comes along I can make the change in the Form itself rather mucking around with the View logic or the validate in Shape Program.
You are already halfway there if you are considering making a class to hold your validation logic this will get you the rest of the way in your new design.