I have a gui that I am working with, modifying it to suit a particular use-case.
I am doing a sql query, and populating the $table variable with the results
Two columns of data, username, and usercode
This is displaying correctly when the form opens.
The issue is when selecting an item and clicking "OK" the selected value is not
being saved.
I think its due to the multiple columns?
I am trying to select the "user_code" value only, the name is just for a
friendly lookup method.
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Select Username"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$username=$objListView.SelectedItem;$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please select the Correct Username:"
$objForm.Controls.Add($objLabel)
$objListView = New-Object System.Windows.Forms.ListView
$objListView.Location = New-Object System.Drawing.Size(10,40)
$objListView.Size = New-Object System.Drawing.Size(260,20)
$objListView.Height = 80
$objListView.View = 'Details'
$objListView.Columns.Add('User_name')
$objListView.Columns.Add('User_code')
Foreach ($name in $table)
{
$item = New-Object System.Windows.Forms.ListviewItem($name.user_name)
$item.SubItems.add($name.user_code)
$objListView.Items.Add($item)
}
$objForm.Controls.Add($objListView)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1