Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve all outputs from a PowerShell form's dynamic checkbox list, you can follow these steps:

  1. Declare an empty array to store the selected items:
$selectedItems = @()
  1. Bind a script block to the "CheckedChanged" event of the checkboxes:
$checkBoxes.Add_CheckedChanged({
    $checkBox = $this  # current checkbox
    $item = $checkBox.Text  # get the text of the checkbox
    if ($checkBox.Checked) {
        $selectedItems += $item  # add the item to the selected items array
    } else {
        $selectedItems -= $item  # remove the item from the selected items array if it was unchecked
    }
})
  1. When you need to retrieve the selected items, simply access the $selectedItems array:
Write-Host "Selected items: $($selectedItems -join ', ')"