I have some problem with Add_checkStateChanged method (checkbox object) in Powershell. I have some dynamic form where I'm creating group of checkboxes. I do this by using something like that:
New-Variable -Name "checkBox_${item}_${i}" -Value (New-Object System.Windows.Forms.Checkbox)
Also I check activity on this obcjects by:
$checkboxes = (Get-Variable checkBox_*_*)
$checkboxes | ForEach {
$_.Value.Add_CheckStateChanged({
$okButton.Enabled = $True -in $checkboxes.Value.Checked
})
}
Everything works fine when I have created objects on start. But when I create checkboxes dynamically during program works then I have some errors because method Add_CheckStateChanged refers to a non-existent object (checkboxes). Of course program run fine, and check the state of checkboxes, but it also output errors:
Method invocation failed because [System.Boolean] does not contain a mathod named 'Add_CheckStateChanged'
Do You know some way to around this errors (without Out-null) or some way to check state of checkboxes only after creating them.
I also try "try catch" block. But in this situation Add_CheckStateChanged not work properly.
Aucun commentaire:
Enregistrer un commentaire