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.
Windows.Forms.ListView
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.
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.
Re: Windows.Forms.ListView
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
For information on how to script a ListView see: https://info.sapien.com/index.php/guis/ ... ew-control
Re: Windows.Forms.ListView
Can I number every item whit number 1-2-3 "ItemChecked"
Is possible so something like this can work?
#Item 1
And give this the number 1
# Add list items
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
Code: Select all
if($listview1.Items['Item 1'].Checked) {
start-process https://www.google.dk
}
Re: Windows.Forms.ListView
I have tried
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
Now I get and error code:
Cannot index into a null array.
------------------------------------------------------------------------------------
I have then after tried this:
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)
Code: Select all
[b] if($ListView.Items['Item 1'].Checked) {
start-process https://www.google.dk
}
[/b]
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
}
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"
}
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
The name is $1 for Item
# Add list items
# 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)
Last edited by hrlarsen on Mon Aug 06, 2018 2:28 pm, edited 1 time in total.
Re: Windows.Forms.ListView
As standard (name) is $listView.Name = "listView1"
But I have renamed it to = "$1"
What variable code am I missing.
But I have renamed it to = "$1"
What variable code am I missing.
Re: Windows.Forms.ListView
"$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.