Validating tab page controls

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
Lembasts
Posts: 208
Joined: Thu Mar 15, 2012 9:47 am

Validating tab page controls

Post by Lembasts » Sun May 05, 2019 6:49 pm

Greetings,

I have a number of controls on a tab page that have validating events.
When a user leaves that tab page I would like to validate all controls but a tab page does not have a validatechildren event.
So what I have done is to try and call the validating events manually e.g.
$this = $textboxdescription
$notempty_validating.invoke()
The above is a generic validating event used by a number of controls to make sure a particular textbox control is not empty. As its used by a number of controls I have to set the $this variable prior to calling it.
However the invoke doesnt work. It bombs out in my try/catch logic.
Is it actually possible to call all the validating events for controls on a tab page?
Thanks
David

User avatar
Lembasts
Posts: 208
Joined: Thu Mar 15, 2012 9:47 am

Re: Validating tab page controls

Post by Lembasts » Sun May 05, 2019 8:01 pm

I have a good workaround.
As it happens all my validating events call a generic data validation subroutine thus: $_.Cancel = confirm-validdata 'NotEmpty'
So instead of trying to invoke the validating event, I can just call my data validation subroutine directly. That'll do for me.

jvierra
Posts: 13881
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Validating tab page controls

Post by jvierra » Mon May 06, 2019 3:45 am

You cannot set the "$this" variable. It is read-only. It is a reserved variable that is set by the system to the control sending the event.
"ValidateChildren" is not an event it is a method that can be called on a container to cause it to validate all child controls.

https://docs.microsoft.com/en-us/dotnet ... mework-4.8

Tab pages are children of the tab control and tab pages have children. THe "Validating" event is called and not the "Validated" event.

User avatar
Lembasts
Posts: 208
Joined: Thu Mar 15, 2012 9:47 am

Re: Validating tab page controls

Post by Lembasts » Mon May 06, 2019 2:17 pm

Normally you cannot set the $this variable but I cheat :-)
The validating event calls my function which automatically passes the value of $this.
But when I call the same function outside of the validating event, I also pass a control which gets assigned to the variable $this in the function which is fine cause its a different scope.
ANd I know the difference between validating and validated as I have to use both.

Locked