vb.net - Listview - Multi column - Change selection color for the whole row -
i change selection color in listview, default (blue). can not adapt code found needs.
here code closest.
if e.item.selected = true e.graphics.fillrectangle(new solidbrush(color.gray), e.bounds) textrenderer.drawtext(e.graphics, e.item.text, new font(listview2.font, nothing), new point(e.bounds.left + 3, e.bounds.top + 2), color.white) else e.drawdefault = true end if the main problem e.item.text part. doesn't work multi column listview. here result.
before selection : 
...and after : 
is possible preserve values other columns , still have full row selection?
thanks.
the thing keep in mind ownerdraw listview there 2 events respond (or override if subclassing) if control details view: drawcolumnheader , drawsubitem.
drawitem used when control using different view , there no subitems draw.
since subitems(0) same item.text, can use drawsubitem draw item , subitem text. cannot tell snippet located, work:
private sub lv1_drawsubitem(sender object, e drawlistviewsubitemeventargs) handles lv1.drawsubitem ' use sender instead of hardcodes control ref ' can paste lv dim mylv listview = ctype(sender, listview) if e.itemindex > 0 andalso e.item.selected using br new solidbrush(color.gray) e.graphics.fillrectangle(br, e.bounds) end using using fnt new font(mylv .font, nothing) ' use e.subitem.text textrenderer.drawtext(e.graphics, e.subitem.text, fnt, new point(e.bounds.left + 3, e.bounds.top + 2), color.white) end using ' dispose! else e.drawdefault = true end if end sub it appear may using correct event, usingitem.text rather e.subitem.text item text drawn subitems (drawsubitem called many times there subitems).
note wrapped font in using block dispose of it. using limegreen, result:

Comments
Post a Comment