# 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.

Note

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

Me.dataGridView1.GridColor = Color.BlueViolet


### To change the border style of the entire DataGridView control programmatically

• Set the BorderStyle property to one of the BorderStyle enumeration values.

this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;

Me.dataGridView1.BorderStyle = BorderStyle.Fixed3D


### To change the border styles for DataGridView cells programmatically

this.dataGridView1.CellBorderStyle =
DataGridViewCellBorderStyle.None;

With Me.dataGridView1
.CellBorderStyle = DataGridViewCellBorderStyle.None
End With


## Example

private void SetBorderAndGridlineStyles()
{
this.dataGridView1.GridColor = Color.BlueViolet;
this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;
this.dataGridView1.CellBorderStyle =
DataGridViewCellBorderStyle.None;
}

Private Sub SetBorderAndGridlineStyles()

With Me.dataGridView1
.GridColor = Color.BlueViolet
.BorderStyle = BorderStyle.Fixed3D
.CellBorderStyle = DataGridViewCellBorderStyle.None