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.
Set the GridColor property.
this.dataGridView1.GridColor = Color.BlueViolet;
Me.dataGridView1.GridColor = Color.BlueViolet
Set the BorderStyle property to one of the BorderStyle enumeration values.
this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;
Me.dataGridView1.BorderStyle = BorderStyle.Fixed3D
Set the CellBorderStyle, RowHeadersBorderStyle, and ColumnHeadersBorderStyle properties.
this.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None; this.dataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; this.dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
With Me.dataGridView1 .CellBorderStyle = DataGridViewCellBorderStyle.None .RowHeadersBorderStyle = _ DataGridViewHeaderBorderStyle.Single .ColumnHeadersBorderStyle = _ DataGridViewHeaderBorderStyle.Single End With
private void SetBorderAndGridlineStyles()
{
this.dataGridView1.GridColor = Color.BlueViolet;
this.dataGridView1.BorderStyle = BorderStyle.Fixed3D;
this.dataGridView1.CellBorderStyle =
DataGridViewCellBorderStyle.None;
this.dataGridView1.RowHeadersBorderStyle =
DataGridViewHeaderBorderStyle.Single;
this.dataGridView1.ColumnHeadersBorderStyle =
DataGridViewHeaderBorderStyle.Single;
}
Private Sub SetBorderAndGridlineStyles()
With Me.dataGridView1
.GridColor = Color.BlueViolet
.BorderStyle = BorderStyle.Fixed3D
.CellBorderStyle = DataGridViewCellBorderStyle.None
.RowHeadersBorderStyle = _
DataGridViewHeaderBorderStyle.Single
.ColumnHeadersBorderStyle = _
DataGridViewHeaderBorderStyle.Single
End With
End Sub
This example requires:
A DataGridView control named
dataGridView1
.References to the System, System.Windows.Forms, and System.Drawing assemblies.
.NET Desktop feedback feedback
.NET Desktop feedback is an open source project. Select a link to provide feedback: