Page 1 of 2
Windows.Forms.ListView
Posted: Mon Aug 06, 2018 3:32 am
by hrlarsen
Windows.Forms.ListView
I have a button to click that are working fine.
But how do I check
"1 specific ListView Item".
If it is Checked in the checkbox, True / False before going forward.
--------------------------------------------------------------
# Add list items
$ListViewItem = New-Object System.Windows.Forms.ListViewItem("Item 1")
$ListView.Items.Add($ListViewItem)
-------------------------------------------------------------
-------------------------------------------------------------
#Button
$ButtonCheckedItem.add_click({
if($ListViewItem.CheckedItems.Count[1])
{
#perform action test
start-process "
https://www.google.com"
}
$Form.Controls.Add($ButtonCheckedItem)
})
------------------------------------------------------------
What do I need to chance?
And please dont link to online msn I have looked there.
Re: Windows.Forms.ListView
Posted: Mon Aug 06, 2018 5:45 am
by jvierra
You need to enumerate the ListView items collection and test each check or use the "ItemChecked" event to perform an action when a checkbox is checked:
For information on how to script a ListView see:
https://info.sapien.com/index.php/guis/ ... ew-control
Re: Windows.Forms.ListView
Posted: Mon Aug 06, 2018 6:25 am
by hrlarsen
Can I number every item whit number 1-2-3
"ItemChecked"
Is possible so something like this can work?
#Item 1
if ($ListViewItem.ItemChecked($1))
{
#test me out if item 1 checkbox is clicked.
start-process "
https://www.google.dk"
}
And give this the number 1
# Add list items
$ListViewItem = New-Object System.Windows.Forms.ListViewItem("Item 1")
$ListView.Items.Add($ListViewItem)
Re: Windows.Forms.ListView
Posted: Mon Aug 06, 2018 9:40 am
by jvierra
Code: Select all
if($listview1.Items['Item 1'].Checked) {
start-process https://www.google.dk
}
Re: Windows.Forms.ListView
Posted: Mon Aug 06, 2018 11:56 am
by hrlarsen
I have tried
Code: Select all
[b] if($ListView.Items['Item 1'].Checked) {
start-process https://www.google.dk
}
[/b]
But nothing happens when I run it, and click the first item 1.
and click the button. I dont get any error code to check either.
------------------------------------------------------------------------------------
I have then tried this
Code: Select all
if($ListViewItem1.Items['Item 1'].Checked) {
start-process https://www.google.dk
}
Now I get and error code:
Cannot index into a null array.
------------------------------------------------------------------------------------
I have then after tried this:
Code: Select all
if ($ListViewItem1.Checked)
{
#test me
start-process "https://www.google.dk"
}
This work for checking 1 item $ListViewItem1 that i Renamed from $ListViewItem as a test.
But that must be the wrong way to do this?
I dont thing it is the right way, there must be a way to check via a string
$1 = or via
text ("Item 1")
So maybe this need to be transformet or changed to resolved this.
# Add list items
$ListViewItem1 = New-Object System.Windows.Forms.ListViewItem("Item 1")
$ListView.Items.Add($ListViewItem1)
$Form.Controls.Add($ListView)
Re: Windows.Forms.ListView
Posted: Mon Aug 06, 2018 12:22 pm
by jvierra
What is the name of the item. If you didn't set a name then it will be unusable.
Re: Windows.Forms.ListView
Posted: Mon Aug 06, 2018 2:24 pm
by hrlarsen
The name is $1 for Item
# Add list items
Code: Select all
$ListViewItem = New-Object System.Windows.Forms.ListViewItem('Item 1')
$ListView.Items.Add($ListViewItem)
$ListViewItem.Name = '$1'
$Form.Controls.Add($ListView)
Re: Windows.Forms.ListView
Posted: Mon Aug 06, 2018 2:28 pm
by jvierra
What is $1? It is a variable. Look at the name property on the tab to see what the real name is.
Re: Windows.Forms.ListView
Posted: Mon Aug 06, 2018 2:46 pm
by hrlarsen
As standard (name) is $listView.Name = "listView1"
But I have renamed it to = "$1"
What variable code am I missing.
Re: Windows.Forms.ListView
Posted: Mon Aug 06, 2018 3:14 pm
by jvierra
"$1" is not a name. We don't use "$" in names as it mixes them up with variables. Names need to strings that identify things in a meaningful way. "$1" is not meaningful and will result in an empty name.