Context menu on listview

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Linyuu
Posts: 2
Last visit: Fri Aug 11, 2017 2:47 am

Context menu on listview

Post by Linyuu »

Hello !
I'm working on a Powershell v2.0 computer but the script is meant to be executed with powershell 5.0
Both script and Operating system are 64 Bits

I am pretty new to powershell and work on a script that permit users from my company to test servers remotely.
I've been trying for a few days to add the "Start, pause, restart" functions to this ListView, either by context menu or by Buttons.

What i'm struggling with so far is to detect the "click event" in my listview.

$Global:listS = New-Object System.Windows.Forms.ListView
$listS.Location = "5,35"
$listS.Size = "800, 600"
$listS.View = "Details"
$listS.GridLines = $true
$listS.FullRowSelect = $true
$listS.AllowColumnReorder = $true
$listS.Scrollable = $true
$listS.Sorting ='None'
$listS.add_ColumnClick({SortListServices $_.Column})
$PopupServices.Controls.Add($listS)

That's my working listview code right now.

When i click on a line of the listview, it becomes blue highlighted but "$listS.ItemSelected" is always set to the first row of the listview.
edit : $list.SelectedItem

Do you guys have an idea ?
Last edited by Linyuu on Thu Aug 10, 2017 7:28 am, edited 1 time in total.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Context menu on listview

Post by jvierra »

The property is call "SelectedItem"
$list.SelectedItem
User avatar
Linyuu
Posts: 2
Last visit: Fri Aug 11, 2017 2:47 am

Re: Context menu on listview

Post by Linyuu »

Yeah, looks like i messed up writing this down...
Problem is still the same sadly :(
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Context menu on listview

Post by jvierra »

It is not really possible to understand what you are asking. How are you trying to do this. What does a context menu have to do with this. I see no context menu.

Post a simplified PSF file example that shows how your are trying to do this.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Context menu on listview

Post by jvierra »

I suspect that you really want to do this:

This line:
$PopupServices.Controls.Add($listS)

Should be this:
$listS.ContextMenu = $popupServices
This topic is 6 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked