uncheck a check with a command and not trigger an event

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 8 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
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

uncheck a check with a command and not trigger an event

Post by jsira2003@yahoo.com »

In my application different things happen when you check or uncheck a checkbox. However when initializing the checkbox, it also triggers the event. I would like to disable the triggering of the event at a point in time when i reset the state of the checkbox. I guess I am asking how to i disable and re-enable triggering as I apply:

$checkboxSelectedProgram.checked = $false

Perhaps it is a simple as a command before and after the command above.

thanks,
John
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: uncheck a check with a command and not trigger an event

Post by jvierra »

Without some idea of how you are doing this it is not really possible to give you an answer.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: uncheck a check with a command and not trigger an event

Post by jvierra »

Is this what you are asking?
Attachments
Test-CBChanged2.psf
(31.77 KiB) Downloaded 151 times
User avatar
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

Re: uncheck a check with a command and not trigger an event

Post by jsira2003@yahoo.com »

When you click on a check box on a windows form that is an event. There are times when I want to change the state of the checkbox to unchecked without triggering an event. This seems straight forward. I found that by applying the command $checkboxselectedprogram.checked = $false , this triggers an uncheck event. I want to apply the command above and not trigger an event. I believe I have expressed myself clearly.
User avatar
jsira2003@yahoo.com
Posts: 117
Last visit: Tue Jul 11, 2023 6:18 am

Re: uncheck a check with a command and not trigger an event

Post by jsira2003@yahoo.com »

$checkboxSelectedProgram.Enabled = $false
#change the state undetected since checkbox is disabled.
$checkboxSelectedProgram.Checked = $false
$checkboxSelectedProgram.refresh()
$checkboxSelectedProgram.Enabled = $true

This is the answer. I figured out it should be something simple like this.

John
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: uncheck a check with a command and not trigger an event

Post by jvierra »

Disabling a checkbox does not disable events. It only disables the UI. Look at my same. The answer is much easier than you think.

Also - "Refresh()" is not necessary.

Code: Select all

$checkbox1_CheckedChanged={
    if(-not $setting){
	    Write-Host 'changed'
    }
}

$safeSetting_Click={
    $setting = $true
	$checkbox1.Checked = -not $checkbox1.Checked
    $setting = $false
}
This topic is 4 years and 8 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