CheckedChanged wont work

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 2 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
DrKatzmann
Posts: 6
Last visit: Sun Apr 17, 2022 12:17 pm
Has voted: 3 times

CheckedChanged wont work

Post by DrKatzmann »

Can anyone tell me why this aint working?
When changing the selction of the radio buttons, nothing happen at the label (lblTEST).
rdoTest.png
rdoTest.png (5.3 KiB) Viewed 2877 times

Code: Select all

$form1_Load={

}

$rdoTEST1_CheckedChanged = {
	if ($this.Checked -eq $true)
	{
		#Use the Radio Button's Text to set the label
		$lblTEST.Text = "This is a test"
	}
}
I have double checked and cross checked for misspelled variables, but can't find the error.

Thanks in advance
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: CheckedChanged wont work

Post by Alexander Riedel »

[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: CheckedChanged wont work

Post by jvierra »

You have radio buttons and not checkboxes. It is likely the button is not attached to the event.

Try the following and pay close attention to what is happening. It should help you understand how this works and how it can be used correctly.

To use one event to track a group of radio buttons then just save the name of the button checked in a script variable or control
Attachments
Test-Radio.psf
(55.74 KiB) Downloaded 97 times
DrKatzmann
Posts: 6
Last visit: Sun Apr 17, 2022 12:17 pm
Has voted: 3 times

Re: CheckedChanged wont work

Post by DrKatzmann »

Thanks jvierra
I made it work, but only by exporting to *.ps1, adding the lines $radiobutton1.add_CheckedChanged($radiobutton_CheckedChanged) and $radiobutton2.add_CheckedChanged($radiobutton_CheckedChanged) to each radiobutton manually.

Is this the way to make it work or should it be done all from within Powershell Studio?

Btw, thanks for giving "just enough" information.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: CheckedChanged wont work

Post by jvierra »

You will need to spend some time learning how to use PSS before you can understand how these thigs work. The example I posted shows exactly how to do this but the steps will have to be learned from the manual or from a video.

All code can be done from PSS. If you try to copy things from the Internet without first learning both PowerShell and PSS then you will end up where you are now which will end up causing you more confusion in the long run.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: CheckedChanged wont work

Post by Alexander Riedel »

Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: CheckedChanged wont work

Post by jvierra »

Alex,

That is where the original code came from but reading the complete article requires basic understanding f the tool (PSS) and of how PowerShell works.

Maybe we need a better, short beginner document on how to acquire the minimums needed to understand the examples.

Something like David Susskind's "The Theoretical Minimum" series of books on physics. ;)
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: CheckedChanged wont work

Post by Alexander Riedel »

Yeah, I know. We have begun a blog series on very basic things as you may have noticed.
I happily take suggestions on content :D
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 2 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