powershell - CheckedListBox result -


i have checkedlistbox in powershell. when select checkbox text result empty. when select second checkbox first checkbox result text displayed.

i use following code checkedlistbox:

# code $listview = new-object system.windows.forms.checkedlistbox $listview.location = new-object system.drawing.size(10,40)  $listview.size = new-object system.drawing.size(533,325) $listview.checkonclick = $true $listview.add_itemcheck({   ($i = 0; $i - ($listview.items.count-1); $i++)   {     if ($listview.getitemchecked($i))     {      $s = $s + $listview.items[$i].tostring();     }   }      write-host $s   }) 

getitemchecked($i) return correct result item check raised event after event handler has run.

you can inspect event arguments new value of item:

$listview.add_itemcheck({      param($sender,$e)      $s = ""      ($i = 0; $i -le ($listview.items.count-1); $i++)     {         # check if $i index of item (un)checked         if($e.index -eq $i)         {             # inspect new checked-state value             if($e.newvalue -eq 'checked')             {                 $s += $listview.items[$i]             }         }          elseif ($listview.getitemchecked($i))         {              # item checked             $s += $listview.items[$i]         }     }      write-host $s }) 

Comments