Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to detect selection in Combo Boxes instead of click.

$
0
0

I have two groups in a powershell script. One has a series of combo boxes that you select options from, and the second displays the combined result from the selected combo boxes. I was trying to use $combobox1.Add_Click to detect when to update the second group, but the update is not happening when I select an item, it is updating when I click the item (prior to selection). When I review the class for system.windows.forms.combobox, I don't see add_click, so I am guessing that add_click is alias for the eventclick?

  1. What should I be using instead of Add_click?
  2. Am I right that Add_Click is the same as Click?
  3. If Events are not what I should be looking for, how can I list all of the options similar to Add_Click?
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

$Buildings = @("A - Nice","B - Less Nice","C - Terrible")

$objForm = New-Object System.Windows.Forms.Form 
$objForm.Text = "Enter New Computer Name"
$objForm.Size = New-Object System.Drawing.Size(550,400) 
$objForm.StartPosition = "CenterScreen"

#--Group1 Positions----------------------------------
$GPP1 = 25

#-- DefaultMachine Name Group Box----------------------
$Group1 = New-Object System.Windows.Forms.GroupBox
$Group1.Location = New-Object system.drawing.Point(30,30)
$Group1.Size = New-Object system.drawing.size(500,90)
$Group1.Text = "Standard Computer Name"
$Group1.Enabled = $True

#--Building Label------------------------------------
$G1Label1 = New-Object System.Windows.Forms.Label
$G1Label1.Location = New-Object System.drawing.point(40,$GPP1)
$G1Label1.Size = New-Object System.Drawing.size(120,15)
$G1Label1.Text = "Building"
$Group1.Controls.Add($G1Label1)

#--Building------------------------------------------
$G1Combo1 = new-object System.Windows.Forms.ComboBox
$G1Combo1.Location = New-Object system.drawing.Point(40,($GPP1+20))
$G1Combo1.Size = New-Object System.Drawing.Size(120,20)
$G1Combo1.Items.AddRange([system.object[]]($Buildings))
$G1Combo1.SelectedIndex = 0
$Group1.Controls.Add($G1Combo1)

#--Custom Machine Name Group Box-----------------------
$Group3 = New-Object System.Windows.Forms.GroupBox
$Group3.Location = New-Object system.drawing.Point(30,215)
$Group3.Size = New-Object system.drawing.size(500,60)
$Group3.Text = "Custom Computer Name"
$Group3.Enabled =  $False

#--Building Label------------------------------------
$G3Label1 = New-Object System.Windows.Forms.Label
$G3Label1.Location = New-Object System.drawing.point(30,$GPP1)
$G3Label1.Size = New-Object System.Drawing.size(300,15)
$G3Label1.Text = $Null
$Group3.Controls.Add($G3Label1)


$ClickActions = {
         $G3Label1.Text = (($G1Combo1.SelectedItem).substring(0,1))
         }
#--This is where I get the wrong response--------
$G1Combo1.Add_Click($ClickActions)


$ObjForm.Controls.Add($Group1)
$ObjForm.Controls.Add($Group3)
[void] $objForm.ShowDialog()


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>