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.
This topic is 5 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
hrlarsen
Posts: 31
Last visit: Sun Dec 18, 2022 1:47 pm

Re: Windows.Forms.ListView

Post by hrlarsen »

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
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Windows.Forms.ListView

Post by jvierra »

Here is an old demo of uing the checkboxes in a ListView.
Attachments
Demo-ListView.psf
(37.65 KiB) Downloaded 161 times
hrlarsen
Posts: 31
Last visit: Sun Dec 18, 2022 1:47 pm

Re: Windows.Forms.ListView

Post by hrlarsen »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Windows.Forms.ListView

Post by jvierra »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Windows.Forms.ListView

Post by jvierra »

Hint:

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

or

$listViewItem.Group = $listView1.Groups['groupname']
hrlarsen
Posts: 31
Last visit: Sun Dec 18, 2022 1:47 pm

Re: Windows.Forms.ListView

Post by hrlarsen »

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?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Windows.Forms.ListView

Post by jvierra »

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: 31
Last visit: Sun Dec 18, 2022 1:47 pm

Re: Windows.Forms.ListView

Post by hrlarsen »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Windows.Forms.ListView

Post by jvierra »

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']
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Windows.Forms.ListView

Post by jvierra »

Here is a working example of groups.
Attachments
Demo-ListViewIcons.psf
(24.57 KiB) Downloaded 127 times
This topic is 5 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