none
Selected Value of Combo Box is not working RRS feed

  • Question

  • Hi,

    In combox $comboBoxActiveSites there is a value called "Get Deleted Site within Time Frame"

    I am doing something if user selects value "Get Deleted Site within Time Frame" from the combobox

    But this is not working using power shell script,please let me know if I am making any mistake

    if ($comboBoxActiveSites.Text -eq "Get Deleted Site within Time Frame")

    {

    }

    Regards,

    Sudheer


    Thanks & Regards, Sudheer

    Wednesday, April 3, 2019 5:12 PM

Answers

All replies

  • Use:

    $comboBoxActiveSites.SelectedItem


    \_(ツ)_/

    Wednesday, April 3, 2019 5:21 PM
  • Hi,

    I am writing script as below but still not able to get the selected item

    $arrayActiveSites=@("Get Active Site","Get Deleted Site","Get Deleted Site within Time Frame","Get Deleted Site URL")

    $comboBoxActiveSites = New-Object System.Windows.Forms.ComboBox 
    $comboBoxActiveSites.Location = New-Object System.Drawing.Size(10,40) 
    $comboBoxActiveSites.Size = New-Object System.Drawing.Size(180,20) 
    $comboBoxActiveSites.DropDownHeight = 50

    $form.Controls.Add($comboBoxActiveSites)

    foreach ($activeSite in $arrayActiveSites) {
                          $comboBoxActiveSites.Items.Add($activeSite)
                                  }
    $comboBoxActiveSites.add_SelectedIndexChanged({
        
        write-host $comboBoxActiveSites.SelectedItem   
        
    })



    Thanks & Regards, Sudheer

    Thursday, April 4, 2019 4:25 AM
  • Please post your code correctly using the code posting tool provided.


    \_(ツ)_/

    Thursday, April 4, 2019 4:33 AM
  • Works fine for me.

    $arrayActiveSites = @(
        'Get Active Site',
        'Get Deleted Site', 
        'Get Deleted Site within Time Frame', 
        'Get Deleted Site URL'
    )
    Add-Type -AssemblyName System.Windows.Forms
    $form = New-Object System.Windows.Forms.Form
    $comboBoxActiveSites = New-Object System.Windows.Forms.ComboBox
    $form.Controls.Add($comboBoxActiveSites)
    $comboBoxActiveSites.Location = '10, 40'
    $comboBoxActiveSites.Size = '180, 20'
    $comboBoxActiveSites.DropDownHeight = 50
    $comboBoxActiveSites.Items.AddRange($arrayActiveSites)
    $comboBoxActiveSites.add_SelectedIndexChanged({write-host $this.SelectedItem})
    $form.ShowDialog()
    
    


    \_(ツ)_/

    Thursday, April 4, 2019 4:41 AM
  • Sorry,

    I am posting full script as below

    $arrayActiveSites=@("Get Active Site","Get Deleted Site","Get Deleted Site within Time Frame","Get Deleted Site URL")

    $comboBoxActiveSites = New-Object System.Windows.Forms.ComboBox 
    $comboBoxActiveSites.Location = New-Object System.Drawing.Size(10,40) 
    $comboBoxActiveSites.Size = New-Object System.Drawing.Size(180,20) 
    $comboBoxActiveSites.DropDownHeight = 50

    $form.Controls.Add($comboBoxActiveSites)

    foreach ($activeSite in $arrayActiveSites) {
                          $comboBoxActiveSites.Items.Add($activeSite)
                                  }




                                  
    $OneDriveForBusinessPanel = New-Object Windows.forms.panel
    $OneDriveForBusinessPanel.Size = New-Object Drawing.Point 700,500
    $OneDriveForBusinessPanel.Location = New-Object Drawing.Point 230,5
    $OneDriveForBusinessPanel.BorderStyle = "FixedSingle"
    $OneDriveForBusinessPanel.controls.Add($comboBoxActiveSites)
    $form.Controls.Add($OneDriveForBusinessPanel)

    $comboBoxActiveSites.add_SelectedIndexChanged({
        
        write-host $comboBoxActiveSites.SelectedItem    

        
    })  

     

    })

    Regards,

    Sudheer


    Thanks & Regards, Sudheer

    Thursday, April 4, 2019 4:45 AM
  • Once again. Please post your code using the code posting tool provided as I have with my example.  Your post is hard to read and cannot be correctly copied.  That is why we have the tool.


    \_(ツ)_/

    Thursday, April 4, 2019 4:47 AM