DataGridView双下划线Cell

时间:2016-10-15 02:19:16

标签: c# .net winforms datagridview

如何将DataGridView中的单元格加下划线与此图像相似? 我希望在最后一行显示总计,DataGridView中的总单元格应加下划线或单元格底部的某些边框

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以处理CellPainting的{​​{1}}事件,并以这种方式在指定行的底部绘制一个双边框:

DataGridView

enter image description here

另外,您可以将指定行的DividerHeight设置为更大的值:

void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
    if (e.RowIndex == 1 && e.ColumnIndex >= 0)
    {
        e.Paint(e.CellBounds, e.PaintParts);
        e.Graphics.DrawLine(Pens.Black, e.CellBounds.Left,
            e.CellBounds.Bottom - 2, e.CellBounds.Right, e.CellBounds.Bottom - 2);
        e.Graphics.DrawLine(Pens.Black, e.CellBounds.Left,
            e.CellBounds.Bottom - 4, e.CellBounds.Right, e.CellBounds.Bottom - 4);
        e.Handled = true;
    }
}

enter image description here