Page 1 of 1

uncheck a check with a command and not trigger an event

Posted: Tue Jul 09, 2019 11:02 am
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

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

Posted: Tue Jul 09, 2019 11:09 am
by jvierra
Without some idea of how you are doing this it is not really possible to give you an answer.

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

Posted: Tue Jul 09, 2019 11:33 am
by jvierra
Is this what you are asking?

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

Posted: Tue Jul 09, 2019 11:45 am
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.

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

Posted: Tue Jul 09, 2019 3:03 pm
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

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

Posted: Tue Jul 09, 2019 3:24 pm
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
}