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.
Post Reply
User avatar
Linyuu
Posts: 2
Joined: Thu Aug 10, 2017 3:42 am

Context menu on listview

Post by Linyuu » Thu Aug 10, 2017 3:54 am

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.

User avatar
jvierra
Posts: 11150
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Context menu on listview

Post by jvierra » Thu Aug 10, 2017 6:59 am

The property is call "SelectedItem"
$list.SelectedItem

User avatar
Linyuu
Posts: 2
Joined: Thu Aug 10, 2017 3:42 am

Re: Context menu on listview

Post by Linyuu » Thu Aug 10, 2017 7:27 am

Yeah, looks like i messed up writing this down...
Problem is still the same sadly :(

User avatar
jvierra
Posts: 11150
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Context menu on listview

Post by jvierra » Thu Aug 10, 2017 7:37 am

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.

User avatar
jvierra
Posts: 11150
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Context menu on listview

Post by jvierra » Thu Aug 10, 2017 7:49 am

I suspect that you really want to do this:

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

Should be this:
$listS.ContextMenu = $popupServices

Post Reply