Listview background drawing problem C# Winform -
i have little problem listview.
i can load listview items fine, when set background color doesn't draw color way left side of row [the listviewitems loaded listviewsubitems make grid view, first column shows error]. there a narrow strip doesn't paint. width of strip approximately same row header if had row header.
if have thought on can done make background draw i'd love hear it.
now try new idea, i'm offering ten vote bounty first solution still has me using awful construct of mess of pseudo grid view. [i love legacy code.]
edit:
here sample exhibits problem.
public partial class form1 : form { public form1() { initializecomponent(); listview lv = new listview(); lv.dock = system.windows.forms.dockstyle.fill; lv.fullrowselect = true; lv.gridlines = true; lv.hideselection = false; lv.location = new system.drawing.point(0, 0); lv.tabindex = 0; lv.view = system.windows.forms.view.details; lv.allowcolumnreorder = true; this.controls.add(lv); lv.multiselect = true; columnheader ch = new columnheader(); ch.name = "foo"; ch.text = "foo"; ch.width = 40; ch.textalign = horizontalalignment.left; lv.columns.add(ch); columnheader ch2 = new columnheader(); ch.name = "bar"; ch.text = "bar"; ch.width = 40; ch.textalign = horizontalalignment.left; lv.columns.add(ch2); lv.beginupdate(); (int = 0; < 3; i++) { listviewitem lvi = new listviewitem("1", "2"); lvi.backcolor = color.black; lvi.forecolor = color.white; lv.items.add(lvi); } lv.endupdate(); } }
ah! see :}
you want hacky? present unto following:
... lv.ownerdraw = true; lv.drawitem += new drawlistviewitemeventhandler( lv_drawitem ); ... void lv_drawitem( object sender, drawlistviewitemeventargs e ) { rectangle foo = e.bounds; foo.offset( -10, 0 ); e.graphics.fillrectangle( new solidbrush( e.item.backcolor ), foo ); e.drawdefault = true; }
for more inventive - , no less hacky - approach, try utilising background image of listview ;)
Comments
Post a Comment