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.
This topic is 4 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Lembasts
Posts: 406
Last visit: Mon Apr 15, 2024 3:12 pm
Has voted: 1 time
Been upvoted: 1 time

Validating tab page controls

Post by Lembasts »

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: 406
Last visit: Mon Apr 15, 2024 3:12 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Validating tab page controls

Post by Lembasts »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Validating tab page controls

Post by jvierra »

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: 406
Last visit: Mon Apr 15, 2024 3:12 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Validating tab page controls

Post by Lembasts »

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.
This topic is 4 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked