Is there any way to force control validation in .NET CF? In full .NET there is the Validate() method, but it is missing from CF.
I’m trying to make a control bind data back to the model when closing the form, but clicking the main menu button doesn’t seem to steal focus from the control and the Validating and Validated events don’t fire.
Do you know of any workarounds for this problem?
I struggled with very same issue about a year ago. Everything I found on the web was pretty nasty (i.e. iterate over controls and catch every control focus thus firing validate event or some solution that heavily relied on pinvoke or reflection – I don’t exactly remember).
I ended up creating wrappers that included Validate method for my textboxes etc. and keeping collection of this wrappers. This way, I could iterate over my wrappers and call validate for every control.
That solution worked fine. First I tried the solution with programmatically catching every control focus but I had lots of problems with it. After wasting some time trying to improve this solution I decided to create these wrappers and this was very good decision.
UPDATE
Here how it looked like. Inform I declare list of controls that need to be validated:
In constructor I add controls to the list:
Then I am able to validate the form:
And textbox with validation looks like this: