Hello all,
I recently received some great help from Boe and Rhys to get a "Select All" Checkbox working in a Form in PowerShell:
However, I'm having trouble following the logic the form takes when I click "Select All". Here is the code:
[void][system.reflection.assembly]::LoadWithPartialName("System.Drawing") [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $objForm3b = New-Object System.Windows.Forms.Form $objForm3b.Text = "Test" $objForm3b.Size = New-Object System.Drawing.Size(250,150) $objForm3b.StartPosition = "CenterScreen" $CheckedListBox3b = New-Object System.Windows.Forms.CheckedListBox $CheckedListBox3b.Location = New-Object System.Drawing.Size(12,12) $CheckedListBox3b.size = New-Object System.Drawing.Size(100,50) $CheckedListBox3b.CheckOnClick = $true $CheckedListBox3b.Items.Add("Select All") > $null $CheckedListBox3b.ClearSelected() $CheckedListBox3b.Add_click({ If($this.selecteditem -eq "Select All"){ If($CheckedListBox3b.CheckedItems[0] -eq "Select All"){ write-host "checked" } Else{write-host "not checked"} } }) $objForm3b.Controls.Add($CheckedListBox3b) $Form3b = $objForm3b.ShowDialog()
In reading the code in the "Add_Click" section, it would appear to be saying that "If the first item checked is 'Select All', then write-host 'checked'. Otherwise, write-host 'not checked'. However, the behavior of the script is the exact opposite, such that it outputs "checked" when you uncheck "select all".
Could someone please walk through the code logic so I can get a better understanding of the logic the script is using?