Oh, neat.


Didn't know gridview could do that.

That saves me a ton of code. :)

________________________________
From: [email protected] [[email protected]] on behalf 
of David O'Brien [[email protected]]
Sent: Wednesday, September 30, 2015 8:27 AM
To: [email protected]
Subject: Re: [powershell] Help with ListView

Hi,

Check out this article: 
http://www.david-obrien.net/2014/12/install-windows-features-powershell-clicking

This should explain what Keith is getting at ;)

Cheers
David

From: <[email protected]<mailto:[email protected]>> 
on behalf of "Keith Garner (Hotmail)"
Reply-To: 
"[email protected]<mailto:[email protected]>"
Date: Wednesday, 30 September 2015 7:49 am
To: "[email protected]<mailto:[email protected]>"
Subject: RE: [powershell] Help with ListView

That shouldn’t, by itself, prevent you from using out-gridview.

From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of 
[email protected]<mailto:[email protected]>
Sent: Tuesday, September 29, 2015 2:43 PM
To: [email protected]<mailto:[email protected]>
Subject: RE: [powershell] Help with ListView


Regarding the out-gridview, that's not an option.

I am grabbing a list of users from sql, and selecting one. Based on that 
selection, a variable is set that is used later in the script.

________________________________
From:[email protected]<mailto:[email protected]> 
[[email protected]<mailto:[email protected]>] on 
behalf of Keith Garner (Hotmail) 
[[email protected]<mailto:[email protected]>]
Sent: Tuesday, September 29, 2015 4:56 PM
To: [email protected]<mailto:[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]> 
[mailto:[email protected]] On Behalf Of 
[email protected]<mailto:[email protected]>
Sent: Tuesday, September 29, 2015 1:18 PM
To: [email protected]<mailto:[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-ObjectSystem.Windows.Forms.Form

$objForm.Text ="Select Username"

$objForm.Size =New-ObjectSystem.Drawing.Size(300,200)

$objForm.StartPosition ="CenterScreen"

$OKButton=New-ObjectSystem.Windows.Forms.Button

$OKButton.Location =New-ObjectSystem.Drawing.Size(75,120)

$OKButton.Size =New-ObjectSystem.Drawing.Size(75,23)

$OKButton.Text ="OK"

$OKButton.Add_Click({$username=$objListView.SelectedItem;$objForm.Close()})

$objForm.Controls.Add($OKButton)

$CancelButton=New-ObjectSystem.Windows.Forms.Button

$CancelButton.Location =New-ObjectSystem.Drawing.Size(150,120)

$CancelButton.Size =New-ObjectSystem.Drawing.Size(75,23)

$CancelButton.Text ="Cancel"

$CancelButton.Add_Click({$objForm.Close()})

$objForm.Controls.Add($CancelButton)

$objLabel=New-ObjectSystem.Windows.Forms.Label

$objLabel.Location =New-ObjectSystem.Drawing.Size(10,20)

$objLabel.Size =New-ObjectSystem.Drawing.Size(280,20)

$objLabel.Text ="Please select the Correct Username:"

$objForm.Controls.Add($objLabel)

$objListView=New-ObjectSystem.Windows.Forms.ListView

$objListView.Location =New-ObjectSystem.Drawing.Size(10,40)

$objListView.Size =New-ObjectSystem.Drawing.Size(260,20)

$objListView.Height =80

$objListView.View ='Details'

$objListView.Columns.Add('User_name')

$objListView.Columns.Add('User_code')

Foreach ($namein$table)

{

$item=New-ObjectSystem.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

================================================
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