How to: Change the Border and Gridline Styles in the Windows Forms DataGridView Control

With the DataGridView control, you can customize the appearance of the control's border and gridlines to improve the user experience. You can modify the gridline color and the control border style in addition to the border styles for the cells within the control. You can also apply different cell border styles for ordinary cells, row header cells, and column header cells.


The gridline color is used only with the Single, SingleHorizontal, and SingleVertical values of the DataGridViewCellBorderStyle enumeration and the Single value of the DataGridViewHeaderBorderStyle enumeration. The other values of these enumerations use colors specified by the operating system. Additionally, when visual styles are enabled on Windows XP and the Windows Server 2003 family through the System.Windows.Forms.Application.EnableVisualStyles method, the GridColor property value is not used.

To change the gridline color programmatically

  • Set the GridColor property.

    this.dataGridView1.GridColor = Color.BlueViolet;

To change the border style of the entire DataGridView control programmatically

To change the border styles for DataGridView cells programmatically


private void SetBorderAndGridlineStyles()
    this.dataGridView1.GridColor = Color.BlueViolet;
    this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;
    this.dataGridView1.CellBorderStyle =
    this.dataGridView1.RowHeadersBorderStyle =
    this.dataGridView1.ColumnHeadersBorderStyle =

Compiling the Code

This example requires:

See Also