在Winform的开发中,会遇到根据内容设置DataGridView的行的线为虚线,DataGridView自带不具有虚线功能,你能够重写,也能够其余方法,在这里我使用DrawBorder的方法。
1、关闭DataGridView自带的CellBorderStyle,即设置DataGridView的CellBorderStyle为none。orm
2、在行的绘制事件添加如下代码blog
private void dgvContent_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { //条件判断 if (e.RowIndex > 0 && dgvContent[0, e.RowIndex].Value != null) { //获取行边界 Rectangle cellRect = e.RowBounds; //绘制边框 ControlPaint.DrawBorder(e.Graphics, cellRect, Color.LightGray, 0, ButtonBorderStyle.Dashed, Color.LightGray, 1, ButtonBorderStyle.Dashed, Color.LightGray, 0, ButtonBorderStyle.Dashed, Color.LightGray, 0, ButtonBorderStyle.Dashed); } }完成,手工