I have a drop down list that's populated by a CSV file. Next to the list is a 'Go' button that puts the CSV info into the rest of the program based on what's chosen. When a value is selected I'd like to be able to press Enter instead of clicking Go and have the Enter key basically call the button click. Am I thinking of that correctly? I've found a few things, but none of them have seemed to work. Probably because I don't know where to put it in my code.
Here's the drop down menu and button code...
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 120
$System_Drawing_Size.Height = 20
$label5.Size = $System_Drawing_Size
$label5.Text = "Company Presets:"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 223
$System_Drawing_Point.Y = 18 #545
$label5.Location = $System_Drawing_Point
$label5.DataBindings.DefaultDataSourceUpdateMode = 0
$label5.Name = "label5"
$label5.BackColor = "Transparent"
$form1.Controls.Add($label5)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 225
$System_Drawing_Point.Y = 46 #569
$companybox.Location = $System_Drawing_Point
$companybox.DataBindings.DefaultDataSourceUpdateMode = 0
$companybox.FormattingEnabled = $True
$companybox.Name = "companybox"
$companybox.TabIndex = 18
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 30
$System_Drawing_Size.Width = 260
$companybox.Size = $System_Drawing_Size
$companybox.DropDownHeight = 125
ForEach ($Items in $List) {
$companybox.Items.Add($Items)
}
$companybox.AutoCompleteSource = 'CustomSource'
$companybox.AutoCompleteMode='SuggestAppend'
$companybox.AutoCompleteCustomSource=$autocomplete
$List | % {$companybox.AutoCompleteCustomSource.AddRange($_) }
$Form1.Controls.Add($companybox)
$gobutton.TabIndex = 20
$gobutton.Name = "Go"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 34
$System_Drawing_Size.Height = 23
$gobutton.Size = $System_Drawing_Size
$gobutton.UseVisualStyleBackColor = $True
$gobutton.Text = "Go"
$gobutton.ForeColor = "Black"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 490
$System_Drawing_Point.Y = 44 #567
$gobutton.Location = $System_Drawing_Point
$gobutton.DataBindings.DefaultDataSourceUpdateMode = 0
$gobutton.add_Click($handler_gobutton_Click)
$form1.Controls.Add($gobutton)
Here are three things I've tried. I've put these chunks in the $companybox section, and the $gobutton section, neither seems to work. I've changed the $textbox variable each time, tried changing the &$buttongo_click to $handler_gobutton_click, and $gobutton_click.
$textboxpath_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
if ($_.KeyChar -eq [System.Windows.Forms.Keys]::Enter) {
&$buttonGo_Click
}
}
$textbox1_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs]
if($_.KeyChar -eq 13){
[void][System.Windows.Forms.MessageBox]::Show('Enter key entered'+$_.KeyChar)
}
}
$textbox1_KeyUp=[System.Windows.Forms.KeyEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyEventArgs]
if($_.KeyCode -eq 'Enter')
{
&$button1_Click
}
}
Thanks!
Set the Form's AcceptButton property to the Go button e.g.:
$form1.AcceptButton = $goButton