Page 2 of 2

Re: Windows.Forms.ListView

Posted: Tue Aug 07, 2018 2:19 am
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
}

Re: Windows.Forms.ListView

Posted: Tue Aug 07, 2018 2:48 am
by jvierra
Here is an old demo of uing the checkboxes in a ListView.

Re: Windows.Forms.ListView

Posted: Thu Aug 09, 2018 10:35 am
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.

Re: Windows.Forms.ListView

Posted: Thu Aug 09, 2018 10:43 am
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.

Re: Windows.Forms.ListView

Posted: Thu Aug 09, 2018 10:45 am
by jvierra
Hint:

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

or

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

Re: Windows.Forms.ListView

Posted: Fri Aug 10, 2018 3:44 am
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?

Re: Windows.Forms.ListView

Posted: Fri Aug 10, 2018 8:38 am
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.

Re: Windows.Forms.ListView

Posted: Fri Aug 10, 2018 8:46 am
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.

Re: Windows.Forms.ListView

Posted: Fri Aug 10, 2018 9:05 am
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']

Re: Windows.Forms.ListView

Posted: Fri Aug 10, 2018 9:34 am
by jvierra
Here is a working example of groups.