Thanks for the 2nd pair of eyes.

I figured it would be something simple.



Its about 2,000 lines in total.



________________________________
From: [email protected] [[email protected]] on behalf 
of Keith Garner (Hotmail) [[email protected]]
Sent: Tuesday, September 29, 2015 4:56 PM
To: [email protected]
Subject: RE: [powershell] Help with ListView

Get-Member is your friend.
SelectedItems not SelectedItem


$objListView.SelectedItems.ListView.Items[1].Text



Additionally, If I can be so bold as to suggest, if I were doing this project I 
would use “out-GridView”:


$table | out-gridview -passthru | select-object -ExpandProperty User_code



Easier to maintain moving forwards.
 Just looking at all of that “Forms” code makes my eyes water.  :)

From: [email protected] [mailto:[email protected]] On 
Behalf Of [email protected]
Sent: Tuesday, September 29, 2015 1:18 PM
To: [email protected]
Subject: [powershell] Help with ListView


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

================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1


================================================
Did you know you can also post and find answers on PowerShell in the forums?
http://www.myitforum.com/forums/default.asp?catApp=1

Reply via email to