Windows.Forms.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.
hrlarsen
Posts: 27
Joined: Tue Jul 24, 2018 8:36 pm

Re: Windows.Forms.ListView

Post by hrlarsen » Tue Aug 07, 2018 2:19 am

okay can you show me a example that really work corretly as it was ment to.
The unly solution that I get to work is:

Code: Select all

#listViewItem1 checked
if($listViewItem1.checked -eq $true) { 
do your script
}

 #listViewItem2 checked
if($listViewItem2.checked -eq $true) { 
do your script
}

 # or whit checked
if($listViewItem1.checked) { 
do your script
}

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

Re: Windows.Forms.ListView

Post by jvierra » Tue Aug 07, 2018 2:48 am

Here is an old demo of uing the checkboxes in a ListView.
Attachments
Demo-ListView.psf
(37.65 KiB) Downloaded 2 times

hrlarsen
Posts: 27
Joined: Tue Jul 24, 2018 8:36 pm

Re: Windows.Forms.ListView

Post by hrlarsen » Thu Aug 09, 2018 10:35 am

Thanks

Can you make 1 listview demo like this.
----------
Group1
Checkbox itemtext1
Checkbox itemtext2
Group2
Checkbox itemtext3
Checkbox itemtext4

---------
button here.

If listview items is checked and variable from itemtext1 ok execute.
If listview items is checked and variable from itemtext2 ok execute.
If listview items is checked and variable from itemtext3 ok execute.
If listview items is checked and variable from itemtext4 ok execute.

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

Re: Windows.Forms.ListView

Post by jvierra » Thu Aug 09, 2018 10:43 am

No, but you can. Just read the Spotlight article to see how it is done.

Define your groups and add the items to the group you want them included in.

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

Re: Windows.Forms.ListView

Post by jvierra » Thu Aug 09, 2018 10:45 am

Hint:

$listView1.Items[0].Group = $listView1.Groups[0]

or

$listViewItem.Group = $listView1.Groups['groupname']

hrlarsen
Posts: 27
Joined: Tue Jul 24, 2018 8:36 pm

Re: Windows.Forms.ListView

Post by hrlarsen » Fri Aug 10, 2018 3:44 am

Have been looking at what you said.

STEP1
# Add HEAD columns ListView
$listView.Columns.Add("Header items text")
------------------------------------------------------------------------------
STEP2
# Adds a new group
$listViewGroup1 = New-Object -TypeName 'System.Windows.Forms.ListViewGroup'
$listViewGroup1.Header = 'Group1'
[System.Void]$listView.Groups.Add($listViewGroup1)
------------------------------------------------------------------------------
STEP3
# Add first list items
$listViewItem1 = New-Object System.Windows.Forms.ListViewItem("one")
$listView.Items.Add($listViewItem1)
$listViewItem1.Checked = $False
------------------------------------------------------------------------------
STEP4
# Add first items to Group1
$listViewItem1.Group = $listViewGroup1 # line to add to group
$Form.controls.AddRange(@($listView)) | Out-Null
------------------------------------------------------------------------------
STEP5
# Add button click
$ButtonCheckedItem.add_click({
if($listViewItem1.Checked) {
start-process https://www.google.com
}

output
---------
Headertext
Group1
checkbox itemtext
--------
button click me and do some code action.

Is there an more easy way to do this.
in some off those steps?

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

Re: Windows.Forms.ListView

Post by jvierra » Fri Aug 10, 2018 8:38 am

If you are using PowerShell Studio then just define the groups in PSS and manually add items and specify the group as you crate the item.

hrlarsen
Posts: 27
Joined: Tue Jul 24, 2018 8:36 pm

Re: Windows.Forms.ListView

Post by hrlarsen » Fri Aug 10, 2018 8:46 am

Thanks I am trying to do this in pure code in the editor.
The problem whit the designer is very high.
You cant see any code when you change things, even if you dobbelt clik on the form elements.
You unly get the form or click function top showen, so that part is very limitet in the program.
That is wry I am doing it directly in the code editor part, so I can see it all.

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

Re: Windows.Forms.ListView

Post by jvierra » Fri Aug 10, 2018 9:05 am

Just assign the group to the item.


$listViewItem1 = New-Object System.Windows.Forms.ListViewItem("one")
$listView.Items.Add($listViewItem1)
$listViewItem1.Checked = $False
$listViewItem1.Group = $listview1.Groups['groupname']

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

Re: Windows.Forms.ListView

Post by jvierra » Fri Aug 10, 2018 9:34 am

Here is a working example of groups.
Attachments
Demo-ListViewIcons.psf
(24.57 KiB) Downloaded 1 time

Post Reply