DataGridView double underline Cell

后端 未结 1 906
暖寄归人
暖寄归人 2021-01-24 17:07

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

相关标签:
1条回答
  • 2021-01-24 17:44

    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;
    
    0 讨论(0)
提交回复
热议问题