DataGridView 双下划线单元格 [英] DataGridView double underline Cell
问题描述
如何在 DataGridView
中的单元格中双下划线与此图像类似?
我想在最后一行显示总计,DataGridView
中的总计单元格应该在单元格底部带有下划线或一些边框
你可以处理 DataGridView
的 CellPainting
事件并在指定行的底部绘制双边框 this方式:
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;}}
作为另一个选项,您可以设置
如果要为所有行设置分隔线高度,在添加行之前或设置数据源之前,为RowTemplate
设置DividerHeight
,例如:>
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屋!