【问题标题】:DataGridView double underline CellDataGridView 双下划线单元格
【发布时间】:2016-10-15 02:19:15
【问题描述】:

如何在DataGridView 中与此图片相似的单元格加双下划线?
我想在最后一行显示总计,DataGridView 中的总计单元格应该带有下划线或单元格底部的一些边框

【问题讨论】:

  • 我想在最后一行显示总计,并且 datagridview 中总计的单元格应该带有下划线或单元格底部的一些边框@RezaAghaei

标签: c# .net winforms datagridview


【解决方案1】:

您可以处理DataGridViewCellPainting 事件,并以这种方式在指定行的底部绘制双边框:

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;
    }
}

还可以将指定行的DividerHeight 设置为更大的值:

dataGridView1.Rows[1].DividerHeight = 5; 

如果要为所有行设置分隔符高度,在添加行之前或设置数据源之前,请为RowTemplate设置DividerHeight,例如:

dataGridView1.RowTemplate.DividerHeight = 5;

【讨论】:

    猜你喜欢
    • 2021-11-28
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多