here's have far:
foreach($group in $userbgroups.items) { if($_.state -eq 'selected') { try { $brush = new-object system.drawing.solidbrush([system.drawing.color]::lightblue) $_.graphics.fillrectangle($brush, $_.bounds) } { $brush.dispose() } } elseif($group -eq $lbitem) { try { $brush = new-object system.drawing.solidbrush([system.drawing.color]::lightgreen) $_.graphics.fillrectangle($brush, $_.bounds) } { $brush.dispose() } } } this works part aside case want select item colored green, seems must selecting brief second reverts green. i'm lost causing behavior.
i know if add "or" statements 'selected' logic noaccelerator end coloring rows light blue , when click on them either highlight darker blue or light green if have been color without noaccelerator.
so managed figure out solution problem. modified drawitem event following:
$userbgroups_drawitem=[system.windows.forms.drawitemeventhandler]{ #event argument: $_ = [system.windows.forms.drawitemeventargs] if($userbgroups.items.count -eq 0) {return} $_.drawbackground() $lbitem = $userbgroups.items[$_.index] $itembgcolor = [system.drawing.color]::white if($userbgroups.selecteditems.contains($lbitem)) { $itembgcolor = [system.drawing.color]::lightblue } else { if($userbgroups.items -contains $lbitem) { $itembgcolor = [system.drawing.color]::lightgreen } else { $itembgcolor = [system.drawing.color]::white } } try { $brush = new-object system.drawing.solidbrush($itembgcolor) $_.graphics.fillrectangle($brush, $_.bounds) } { $brush.dispose } $_.graphics.drawstring($lbitem, $_.font, [system.drawing.systembrushes]::controltext, (new-object system.drawing.pointf($_.bounds.x, $_.bounds.y))) } the key code worked missing something. whenever selected item selected different item still keep previous selection. resolve made following selection changed event:
$userbgroups_selectedvaluechanged={ $userbgroups.refresh() } it causes flashing occur after selecting item when redraws workable until can figure out if there's way resolve that.
Comments
Post a Comment