Manu Varghese Manu Varghese - 1 month ago 22
C# Question

DataGridView double underline Cell

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

enter image description here

Answer

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

enter image description here

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

this.categoryDataGridView.Rows[1].DividerHeight = 5; 

enter image description here

Comments