DataGridView双下划线单元格 [英] DataGridView double underline Cell

查看:132
本文介绍了DataGridView双下划线单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 DataGridView 中加下划线的单元格与此图像相似?

我想在最后一行显示合计,而在<$中显示合计的单元格c $ c> DataGridView 应该在单元格底部带有下划线或某些边框



解决方案

您可以处理 DataGridView的 CellPainting 事件并以此方式在指定行的底部绘制一个双边框:

  void dataGridView1_CellPainting(对象发送者,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;
}
}

设置为更大的值:

  dataGridView1.Rows [1] .DividerHeight = 5; 



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

  dataGridView1.RowTemplate.DividerHeight = 5; 


How can double underline cell in DataGridView similar to this image?
I want to show total in last row, and total's cell in DataGridView should be in underlined or some border at bottom of cell

解决方案

You can handle CellPainting event of DataGridView and draw a double border at bottom of the specified row this way:

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

Also as another option you can set DividerHeight of the the specified row to a larger value:

dataGridView1.Rows[1].DividerHeight = 5; 

In case if you want to set divider height for all rows, before adding rows or before setting data source, set the DividerHeight for RowTemplate, for example:

dataGridView1.RowTemplate.DividerHeight = 5;

这篇关于DataGridView双下划线单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆