Working with Powershell and Forms (part 4) – Radio buttons and Grouping

PowerShell – Radio buttons, Forms and Grouping

Radio buttons are another element used when creating forms. They allow an end-user to select one option from a group. For example, you post a question on a form – “Do you like cheese?” – The options for the answer would be “Yes – I like cheese”, “No – I don’t like cheese” or “Sometimes – depending on the type of cheese”. These answers cover all the possible answers to the question. When presented to the end user you only want them to select one option from the group.

To set this up in PowerShell we have to do a few things, create a group for the radio buttons, create the radio buttons and give them values, create the form and add the usual “OK” and “Cancel” buttons. The code for all of this is below.




In the script above I have including a little piece that shows you how to include pop-up windows. Have fun with the script and as always, feel free to comment.

For more information on using PowerShell to create forms please check out these articles:

16 comments

    1. Hi Tom, sorry for the delay in getting back to you. You need to treat the group box as a seperate location – so there will be 2 x 1,1 posistions – the one for the form and the one for the grouped radio buttons. I have updated my script to reflect grouped and non-groups buttons – take a look and feel free to contact me.

  1. Using this method did not seem to restrict a grouped set of radio buttons correctly. When I grouped five radio buttons this way, and then added a sixth radio button outside of this group, it was still considered part of the same group, choice-wise. I couldn’t select it *and* one of the five grouped items, in other words.

    1. Hi Tyler. Sorry for taking so long to get back to you. I have updated my script to include grouped and a non-grouped radio button. The script also deals with default selected choices – take a look and feel free to contact me.

  2. Great info. Lucky me I just found your web site by mistake (stumbleupon).
    We have book-marked it for later!

  3. Good post. I learn something new and challenging on blogs I stumbleupon every day.
    It will always be useful to read content from other
    authors and use a little something from other sites.

  4. Hmm it seems like your blog ate my first comment (it was super
    long) so I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog.
    I as well am an aspiring blog writer but I’m still new to the whole thing.
    Do you have any tips and hints for newbie blog writers? I’d certainly appreciate it.

    1. Hi, If you want to start a blog then the first thing to do is find a topic you really like and something you can talk about all day long. The next part is to write, then write more and then keep writing. The process and followers may be slow (depending on your topic of choice) but keep at it. And when you feel you are getting nothing for your work you need to keep at it. Make the time, write your posts and answer all your comments promptly. Best of luck.

  5. Nice post. I will link user4ws here when they have issues with using forms.
    You might be interested in:
    http://www.sapien.com/blog/topics/user-interface-design-for-administrators/
    http://www.sapien.com/blog/topics/spotlight-on-controls/

    Some additions.
    #1 You do not need to load System.Windows.Drawing for this form.
    #2 It is easier to set the DialogResult as a string:
    $CancelButton.DialogResult=’Cancel’
    #3 It is not necessary to set both the Form and button for the Accept/Cancel options. I find it more convenient to do on the button when it is created. The way you do this affects validation.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.