none
Selecting multiple radio buttons RRS feed

  • Question

  • Hello scripting guys, I have been working on a PowerShell form that will allow my management to run their own ad reports. While creating the front end I ran in to a dilemma. I have 2 radio buttons set up so the users can select the report they want to run, however when I select one the other goes unchecked. Is there a way to select them both?  My script is attached.

    Add-Type -AssemblyName System.Windows.Forms $Font = New-Object System.Drawing.Font("Times New Roman",24,[System.Drawing.FontStyle]::Italic) $Font2 = New-Object System.Drawing.Font("Times New Roman",12,[System.Drawing.FontStyle]::Italic) $Form = New-Object system.Windows.Forms.Form $Form.Text = "AD Report Viewer" $Form.AutoScroll = $True $Form.AutoSize = $True $Form.AutoSizeMode = "GrowAndShrink" $Form.MinimizeBox = $False $Form.MaximizeBox = $False $Form.WindowState = "Normal" $Form.StartPosition = "CenterScreen" $Form.Font = $Font $Header = New-Object System.Windows.Forms.Label $Header.Text = "Active Directory Reports" $Header.AutoSize = $True $Header2 = New-Object System.Windows.Forms.Label $Header2.Text = "Please select the reports to process" $Header2.autosize = $true $Header2.Location = New-Object System.Drawing.Size(10,50) $Header2.Font = $font2 $StaleButton = New-Object System.Windows.Forms.RadioButton $StaleButton.Location = New-Object System.Drawing.Size(10,100) $StaleButton.size = '350,20' $StaleButton.Checked = $false $StaleButton.Text = "Stale Objects." $StaleButton.Font = $font2 $MOSButton = New-Object System.Windows.Forms.RadioButton $MOSButton.Location = New-Object System.Drawing.Size(10,150) $MOSButton.size = '350,20' $MOSButton.Checked = $false $MOSButton.Text = "Missing Operating System." $MOSButton.Font = $font2 $OKButton = new-object System.Windows.Forms.Button $OKButton.Location = '130,200' $OKButton.Size = '100,40' $OKButton.Text = 'Run' $OKButton.add_Click({ if($StaleButton.checked){write-host "button pressed"} if($MOSButton.checked){write-host "button1 pressed"} }) $Form.Controls.Add($Header) $Form.Controls.Add($Header2) $Form.Controls.Add($StaleButton) $form.Controls.Add($MOSButton) $form.Controls.Add($OKButton) $Form.ShowDialog()

    Thank you for your assistance


    Thursday, August 17, 2017 1:34 PM

Answers

  • For what you are doing we normally use checkboxes.  These can be selected as many times as you want.  Group boxes will only create more issues for your form and will require a minimum of two radio buttons in each GB.  If there is only one it can never be de-selected without adding extra code.  CheckBoxes can always be de-selected.

    The best way to handle a list of optional items is to use a CheckedListBox.


    \_(ツ)_/


    • Edited by jrv Thursday, August 17, 2017 2:03 PM
    • Marked as answer by Richardlaw Thursday, August 17, 2017 2:20 PM
    Thursday, August 17, 2017 2:02 PM

All replies

  • If you put the radio buttons in separate group boxes  All radio buttons in the same group box only 1 can be selected.  By putting them in separate group boxes you can give your form more control.  

    https://www.experts-exchange.com/questions/24316509/Multiple-radio-button-2-groups-popup-options-with-Powershell.html

    • Edited by simbrook2 Thursday, August 17, 2017 2:10 PM
    Thursday, August 17, 2017 1:48 PM
  • For what you are doing we normally use checkboxes.  These can be selected as many times as you want.  Group boxes will only create more issues for your form and will require a minimum of two radio buttons in each GB.  If there is only one it can never be de-selected without adding extra code.  CheckBoxes can always be de-selected.

    The best way to handle a list of optional items is to use a CheckedListBox.


    \_(ツ)_/


    • Edited by jrv Thursday, August 17, 2017 2:03 PM
    • Marked as answer by Richardlaw Thursday, August 17, 2017 2:20 PM
    Thursday, August 17, 2017 2:02 PM
  • It seemed that using a checkbox did exactly what I needed thank you for your assistance.
    Thursday, August 17, 2017 2:20 PM
  • for future reading / ref 

    https://www.codeproject.com/articles/799161/dealing-with-powershell-inputs-via-basic-windows-f

    Thursday, August 17, 2017 2:24 PM
  • for future reading / ref 

    https://www.codeproject.com/articles/799161/dealing-with-powershell-inputs-via-basic-windows-f

    Excellent article for new Forms builders.  It is also a good discussion on how to convert C# to PowerShell.


    \_(ツ)_/

    Thursday, August 17, 2017 3:00 PM