Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set header cell borders' color of datagridview

GridColor property of DataGridView can set the color of the grid lines separating the cells of the DataGridView(i.e. borders of every cell).

But it can't change the grid lines' color of header cells(i.e. borders of header cells).
How can I achieve this?
Is there a property that I can use to accomplish this?

1.image of using GridColor property
using <code>GridColor</code> property
2.image of My requirement
enter image description here

As TnTinMn said, the GridColor property only affects cells with CellBorderStyle= DataGridViewCellBorderStyle.Single.
The result is like the following image.
It can't affect the grid lines seperating the header cells.

3.image of using CellBorderStyle property enter image description here

After another try, I succeed.
4.image of using `EnableHeadersVisualStyles = false' enter image description here

(Solution)To summarize:
1.Using GridColor to set the color of grid lines.
2.Set CellBorderStyle,ColumnHeadersBorderStyle,RowHeadersBorderStyle to Single.
3.Set EnableHeadersVisualStyles to false.

like image 403
niaomingjian Avatar asked Sep 12 '16 07:09

niaomingjian


1 Answers

Do the 3 things you listed, and then:

  1. Set CellBorderStyle = DataGridViewCellBorderStyle.Raised - this will allow your colouring to show up in the header only, but because you've now set the body cell border to a 3D type (i.e. raised, sunken etc, not single or none etc), the body's cell will have a system default styling (likely to be grey).

Example

like image 127
Chalky Avatar answered Oct 15 '22 07:10

Chalky