Powershell and Forms (part 2) – Multiple Dropdown lists

Populating a second dropdown list based on your choice in the first dropdown list

Following on from my post yesterday in the week regarding the creating of forms in Powershell, I came across a situation that I need to work on.  I have a form that contains 2 dropdown lists.  The first list contains a list of all the volumes that are on my NetApp filer.  The second dropdown list is populated with a list of all the snapshots from which ever volume I choose in the first dropdown list.

When I change my choice in dropdown list 1 I want to see the contents of dropdown list 2 change and reflect my choice by listing the snapshots of the selected volume in dropdown list 1.




 

So here is the code:

Feel free to leave a comment. I am hoping to have more Powershell/Form related posts soon.

12 comments

  1. I’m having a problem with the next drop down. It doesn’t add the value into anything, Am I doing something wrong?

    $DropDownLabelTitle = New-Object System.Windows.Forms.Label
    $DropDownLabelTitle.Location = New-Object System.Drawing.Size(10,170)
    $DropDownLabelTitle.Size = New-Object System.Drawing.Size(280,20)
    $DropDownLabelTitle.Text = “Please Select the Title from the Drop Down List: ”
    $objForm.Controls.Add($DropDownLabelTitle)

    [array]$DropDownArrayTitle = “Title1”, “Title2”, “Title3”
    $DropDownTitle = New-Object System.Windows.Forms.ComboBox
    $DropDownTitle.Location = New-Object System.Drawing.Size(10,190)
    $DropDownTitle.Size = New-Object System.Drawing.Size(260,20)
    ForEach ($TitleDrop in $DropDownArrayTitle){
    $DropDownTitle.Items.Add($TitleDrop)
    }
    $objForm.Controls.Add($DropDownTitle)

    $DropDownTitle.Add_SelectedIndexChanged({
    If ($DropDownTitle.Text -eq “Title1”){$DropDownLabelRank = New-Object System.Windows.Forms.Label
    $DropDownLabelRank.Location = New-Object System.Drawing.Size(10,220)
    $DropDownLabelRank.Size = New-Object System.Drawing.Size(280,20)
    $DropDownLabelRank.Text = “Please Select the Name from the Drop Down List: ”
    $objForm.Controls.Add($DropDownLabelRank)

    [array]$DropDownArrayRank = “Something1”, “Something2”, “Something3”
    $DropDownRank = New-Object System.Windows.Forms.ComboBox
    $DropDownRank.Location = New-Object System.Drawing.Size(10,240)
    $DropDownRank.Size = New-Object System.Drawing.Size(260,20)
    ForEach ($RankDrop in $DropDownArrayRank){
    $DropDownRank.Items.Add($RankDrop)
    }$objForm.Controls.Add($DropDownRank)}
    ElseIf ($DropDownTitle.Text -eq “Title2”){$DropDownLabelRank = New-Object System.Windows.Forms.Label
    $DropDownLabelRank.Location = New-Object System.Drawing.Size(10,220)
    $DropDownLabelRank.Size = New-Object System.Drawing.Size(280,20)
    $DropDownLabelRank.Text = “Please Select the Something from the Drop Down List: ”
    $objForm.Controls.Add($DropDownLabelRank)

    [array]$DropDownArrayRank = “SomethingElse”
    $DropDownRank = New-Object System.Windows.Forms.ComboBox
    $DropDownRank.Location = New-Object System.Drawing.Size(10,240)
    $DropDownRank.Size = New-Object System.Drawing.Size(260,20)
    ForEach ($RankDrop in $DropDownArrayRank){
    $DropDownRank.Items.Add($RankDrop)
    }$objForm.Controls.Add($DropDownRank)}
    ElseIf ($DropDownTitle.Text -eq “Title3”){
    $DropDownLabelRank = New-Object System.Windows.Forms.Label
    $DropDownLabelRank.Location = New-Object System.Drawing.Size(10,220)
    $DropDownLabelRank.Size = New-Object System.Drawing.Size(280,20)
    $DropDownLabelRank.Text = “Please Select the SomethingMore from the Drop Down List: ”
    $objForm.Controls.Add($DropDownLabelRank)

    [array]$DropDownArrayRank = “SomethingMore1”, “SomethingMore2”, “SomethingMore3”
    $DropDownRank = New-Object System.Windows.Forms.ComboBox
    $DropDownRank.Location = New-Object System.Drawing.Size(10,240)
    $DropDownRank.Size = New-Object System.Drawing.Size(260,20)
    ForEach ($RankDrop in $DropDownArrayRank){
    $DropDownRank.Items.Add($RankDrop)
    }$objForm.Controls.Add($DropDownRank)}
    })

  2. Just wish to say your article is as amazing. The clarity in your post is
    simply cool and i can assume you’re an expert on this subject.

    Well with your permission let me to grab your RSS feed to keep updated with forthcoming post.
    Thanks a million and please keep up the enjoyable work.

  3. Excellent blog here! Also your website loads up fast! What host
    are you using? Should I buy your affiliate connect to your host?
    I wish my website loaded as quickly as yours lol

  4. I am genuinely delighted to glance at this website posts which carries tons of useful data,
    thanks for providing these kinds of data.

  5. I am actually pleased to glance at this weblog posts which consists of lots
    of helpful data, thanks for providing these information.

  6. you are really a good webmaster. The web
    site loading velocity is amazing. It sort of feels that
    you’re doing any unique trick. Also, The contents are masterwork.
    you have performed a excellent job on this topic!

  7. hi!,I like your writing so so much! proportion we communicate more about your post on AOL?
    I require a specialist in this house to resolve my problem.
    Maybe that’s you! Having a look forward to look you.

  8. Do you have a spam issue on this site; I also am a blogger, and I
    was wondering your situation; we have created some nice practices and
    we are looking to trade methods with others, please shoot me an e-mail if
    interested.

  9. Hello! This post couldn’t be written any better!
    Reading through this post reminds me of my previous room mate!

    He always kept talking about this. I will forward this page to
    him. Pretty sure he will have a good read. Thanks for sharing!

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.