c# - Error with e.PaintCells() not painting cells when overriding DataGridViewRow.OnRowPrePaint -
i'm trying control painting of datagridviewrows in derived datagridview overriding onrowprepaint
method. test approach trying paint cells contents , background using eventargs
paint methods e.g. e.paintcells()
or e.paintcellsbackground()
, setting eventargs.handled = true
prevent of other paint methods firing.
my code far is:
protected override void onrowprepaint(datagridviewrowprepainteventargs e) { using (solidbrush brush = new solidbrush(color.blue)) { e.graphics.fillrectangle(brush, e.rowbounds); } e.paintcellsbackground(e.rowbounds, true); e.paintcells(e.rowbounds, e.paintparts); e.handled = true; }
i expecting colour row blue , e.paintcellsbackground()
, e.paintcells()
methods paint cells ontop of blue background presented blue rows nothing else painted. remarks on msdn article on paintcellsbackground
reads
use paintcellsbackground method when draw datagridviewrow , cells' contents yourself. if manually paint entire row , cells' contents, set handledeventargs.handled property true. when handledeventargs.handled true, cellpainting , rowpostpaint events not occur.
which leads me believe should able i'm hoping?
thank feedback, cannot find article read can set e.handled = true
in oncellpainting
, onrowpostpaint
, handle of painting in onrowprepaint
didn't appreciate meant all of painting.
when call of paint methods in onrowprepaint
, oncellpainting
called , appears handle actual painting had disabled in code expecting e.paintcells()
method painting.
example 1
class mydatagridview : datagridview { protected override void onrowprepaint(datagridviewrowprepainteventargs e) { e.paintcells(e.rowbounds, e.paintparts); e.paintheader(true); e.handled = true; } protected override void oncellpainting(datagridviewcellpaintingeventargs e) { base.oncellpainting(e); } }
in example onrowprepaint
paints cells , headers , oncellpainting
fires painting , datagridview
paints expected
example 2
class mydatagridview : datagridview { protected override void onrowprepaint(datagridviewrowprepainteventargs e) { e.paintcells(e.rowbounds, e.paintparts); e.paintheader(true); e.handled = true; } protected override void oncellpainting(datagridviewcellpaintingeventargs e) { e.handled = true; } }
in example onrowprepaint
attempts paint cells , headers when oncellpainting
triggered handled set true , nothing gets painted, resulting in blank datagridview
example 3
class mydatagridview : datagridview { protected override void onrowprepaint(datagridviewrowprepainteventargs e) { e.handled = true; } protected override void oncellpainting(datagridviewcellpaintingeventargs e) { base.oncellpainting(e); } }
in final example onrowprepaint
handled without of paint methods being called , oncellpaint
never fired paint of row contents, column headers painted nothing else.
the key understanding how onrowprepaint
, oncellpainting
, onrowpostpaint
tie together.
Comments
Post a Comment