With Powershell I have a Windows form, dynamically generating several text boxes. I use a validation on each textbox, then use an ErrorProvider to alert if the validation fails.
This is working fine for displaying the error '!' notification. Is there a way to check how many errors are left?
My pseudo-code would say:
Or do I need to maintain a separate logic to see when the errors have been rectified? (The ErrorProvider check below is just a placeholder, I have no idea what to put there!)
$ButtonOK.Add_Click({
$objectList | where {$_ -is [System.Windows.Forms.TextBox] } | foreach-object {
Validate-Input $_
}
if ($ErrorProvider -eq $null) { #This is where I'm stuck
$Form.Close()
}
})
So judging from the response here there is no built in way to reference the amount of errors remaining. Taking the advice of that thread and porting it to Powershell I implemented the following:
When setting or clearing an error use the following:
Set an error: $errTable.set_item("$($curTB.name)","1")
Clearing an error: $errTable.remove("$($curTB.name)")
Use the following code in the 'add_click' section:
If ($errTable.count -le "0") { $form.close() }
Seems to work well and be pretty shorthand.