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.
Locked
User avatar
jsira2003@yahoo.com
Posts: 112
Joined: Fri Apr 07, 2017 9:47 am

uncheck a check with a command and not trigger an event

Post by jsira2003@yahoo.com » Tue Jul 09, 2019 11:02 am

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

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Tue Jul 09, 2019 11:09 am

Without some idea of how you are doing this it is not really possible to give you an answer.

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Tue Jul 09, 2019 11:33 am

Is this what you are asking?
Attachments
Test-CBChanged2.psf
(31.77 KiB) Downloaded 8 times

User avatar
jsira2003@yahoo.com
Posts: 112
Joined: Fri Apr 07, 2017 9:47 am

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

Post by jsira2003@yahoo.com » Tue Jul 09, 2019 11:45 am

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: 112
Joined: Fri Apr 07, 2017 9:47 am

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

Post by jsira2003@yahoo.com » Tue Jul 09, 2019 3:03 pm

$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

User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Tue Jul 09, 2019 3:24 pm

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
}

Locked