title: How to create CheckBox automatically using PowerShell?
body: <p>I want to create checkbox automatically consider to the total a file inside a folder I selected.
  In my script, the checkbox always create one checkbox, but my file more than one. And the checkbox always appear before I select the folder from listbox. Please give me advice if anyone know about this, Thank you so much.
  This is the result look like</p>
  
  <p><a href="https://i.stack.imgur.com/lngqh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lngqh.png" alt="enter image description here"></a></p>
  
  <pre><code>$objForm = New-Object System.Windows.Forms.Form
  $objForm.Text = "Select a Computer"
  $objForm.Size = New-Object System.Drawing.Size(500,700)
  $objForm.StartPosition = "CenterScreen"
  $objForm.Text = "Test"
  $objListBox = New-Object System.Windows.Forms.ListBox
  $objListBox.Location = New-Object System.Drawing.Size(10,70)
  $objListBox.Size = New-Object System.Drawing.Size(260,30)
  $objListBox.Height = 250
  $objListBox.add_SelectedIndexChanged($SelectedFile)
  $objForm.Controls.Add($objListBox)
  
  $objChktBox = New-Object System.Windows.Forms.CheckBox
  $objChktBox.Location = New-Object System.Drawing.Size(10,400)
  $objChktBox.Size = New-Object System.Drawing.Size(400,3000)
  $objChktBox.Height = 200
  $objForm.Controls.Add($objChktBox)
  # Populate list.
  @(Get-ChildItem -Directory ".\").Name | ForEach-Object {[void] $objListBox.Items.Add($_)}
  $SelectedFile= 
  {
  $objChktBox.Text = (Get-ChildItem $objListbox.SelectedItem)
  }
  $objForm.ShowDialog()
  </code></pre>