2016-11-07 回答
e.columnindex == 3
只会在第三列触发的paint事件中调用,也就是说,如果点击columnindex =2的单元格触发paint时,你的代码不起作用,会实用datagridview2的默认样式绘制.
e.cellbounds,因为上面是第三列所以e.cellbounds始终是第三列的bounds
--参考
if(e.columnindex>=0&&e.columnindex < 4 && e.rowindex == 2)
{
rectangle re =datagridview1.getcelldisplayrectangle(0,e.rowindex,false);
re.width = re.width + datagridview1.columns[1].width + datagridview1.columns[2].width + datagridview1.columns[3].width;
e.graphics.fillrectangle(brushes.yellow,re);
pen pen = new pen(datagridview1.backgroundcolor,1);
pen.dashstyle = system.drawing.drawing2d.dashstyle.solid;
e.graphics.drawline(pen,re.x,re.y + re.height - 1,re.x + re.width,re.y + re.height - 1);
e.graphics.drawline(pen,re.x + re.width - 1,re.y,re.x + re.width - 1,re