Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Trying to pull currently selected item from DropDown ComboBox in Powershell

$
0
0

Greetings! I'm currently attempting to write a script that pulls the names of companies from a .csv then executes an install based on the selected company in the dropdown box. I'm pretty mediocre at scripting though so this has been an endeavor.

I have the box working and pulling the company names just fine, but for the life of me I cannot get the function to pull the value to work. I've attempted to change the script to just output the name selected and update a label but it doesn't seem to be outputting anything at all. No errors either. Just a whole lotta nothing.

Clear button works fine though lol.

Here's what I currently have...

$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath

###initialform

Add-Type -assembly System.Windows.Forms
$main_form = New-Object System.Windows.Forms.Form
$main_form.Text ='Install Script'
$main_form.Width = 550
$main_form.Height = 110

###functions

function Clear-Form{

$cbxCust.SelectedIndex = -1
$cbxCust.SelectedItem = ""

Clear-Host

}

function DataRun {

$cbxCust.add_SelectedIndexChanged(
{
write-host $cbxCust.SelectedItems.ToString()
$CustChoice = $cbxCust.SelectedItems
$Label2.Text = "$CustChoice"
})

}

###combobox

$cbxCust = New-Object System.Windows.Forms.ComboBox
$cbxCust.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$cbxCust.Width = 300
$Customers = Import-CSV $dir\CurrentCustomers.csv | %{$cbxCust.Items.Add($_.CustomerName)}
$cbxCust.Location = New-Object System.Drawing.Point(60,10)
$main_form.Controls.Add($cbxCust)

###label2

$Label2 = New-Object System.Windows.Forms.Label
$Label2.Text = "Select a customer"
$Label2.Location  = New-Object System.Drawing.Point(0,40)
$Label2.AutoSize = $true
$main_form.Controls.Add($Label2)

###It's a button, don't get too excited...

$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(400,10)
$Button.Size = New-Object System.Drawing.Size(120,23)
$Button.Text = "Select"
$Button.Add_Click({$DataRun})
$main_form.Controls.Add($Button)

###clear
$ClearButton = New-Object System.Windows.Forms.Button
$ClearButton.Location = New-Object System.Drawing.Size(400,35)
$ClearButton.Size = New-Object System.Drawing.Size(120,23)
$ClearButton.Text = "Clear"
$ClearButton.Add_Click({Clear-Form})
$main_form.controls.Add($ClearButton)

$main_form.ShowDialog()

Any help at all would be great! Thanks ahead of time!


Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

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