Hi guys !
I'd like to use both selection mode at the same time in a listview ( SelectedItems + CheckedItems ) and save the pcname inside a variable
For example i want to select pc-w7 and pc-w7x86 ( with selecteditems )
and w10-1 ( with checkeditems )
Image: //static.spiceworks.com/shared/post/0024/1507/a.jpg
i wrote this, but if i change the selection, there are multiple items with the same name
Powershell
function USER_PC_SELECT {
if ($listview2.CheckedItems.Count -gt 0 -or $listview2.SelectedItems.Count -gt 0){
$Global:SelectedComputer += $listview2.CheckedItems | foreach {$_.text}
$Global:SelectedComputer += $listview2.SelectedItems.text
Write-Host -ForegroundColor White "Selezionato/i computer: " -NoNewline ; Write-Host -ForegroundColor Green $Global:SelectedComputer
}
}
Use SelectedItems and CheckedItems at the same time
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: Use SelectedItems and CheckedItems at the same time
This is could be the answer ?
There's a better method ?
There's a better method ?
- function USER_PC_SELECT {
- if ($listview2.CheckedItems.Count -gt 0 -or $listview2.SelectedItems.Count -gt 0){
- $Global:SelectedComputer = @()
- foreach ($item in $listview2.CheckedItems.text){
- if ($Global:SelectedComputer -notcontains $item){
- $Global:SelectedComputer += $item
- }
- }
- foreach ($item in $listview2.SelectedItems.text){
- if ($Global:SelectedComputer -notcontains $item){
- $Global:SelectedComputer += $item
- }
- }
- }