DataGridView.ColumnHeadersBorderStyle Property
Gets the border style applied to the column headers.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
'Declaration <BrowsableAttribute(True)> _ Public Property ColumnHeadersBorderStyle As DataGridViewHeaderBorderStyle 'Usage Dim instance As DataGridView Dim value As DataGridViewHeaderBorderStyle value = instance.ColumnHeadersBorderStyle instance.ColumnHeadersBorderStyle = value
Property Value
Type: System.Windows.Forms.DataGridViewHeaderBorderStyleOne of the DataGridViewHeaderBorderStyle values.
| Exception | Condition |
|---|---|
| InvalidEnumArgumentException | The specified value when setting this property is not a valid DataGridViewHeaderBorderStyle value. |
| ArgumentException | The specified value when setting this property is Custom. |
If the ColumnHeadersBorderStyle property is set to anything other than Single, the GridColor property must be a system color.
You cannot set this property to the Custom value, which is a read-only value indicating that the border style has been customized through the use of the AdvancedColumnHeadersBorderStyle property.
Note: |
|---|
If visual styles are enabled for the application through the Application.EnableVisualStyles method and the EnableHeadersVisualStyles property is true, the column headers are painted using the current theme. In this case, the value of the ColumnHeadersBorderStyle property is ignored for all column headers except the TopLeftHeaderCell, to which the theme is not applied. |
The following code example demonstrates how to set the ColumnHeadersDefaultCellStyle, AutoSizeRowsMode, ColumnHeadersBorderStyle, CellBorderStyle, GridColor, BackgroundColor, RowHeadersVisible, SelectionMode, ColumnCount, and MultiSelect properties. In addition, the code example demonstrates how to set the DataGridViewColumn.Name and DataGridViewColumn.DefaultCellStyle properties. To run this example, paste the code into a form that contains a DataGridView named dataGridView1, and then call the SetUpDataGridView method from the form's constructor or Load event handler. Ensure all events are associated with their event handlers.
Private Sub SetUpDataGridView() Me.Controls.Add(dataGridView1) dataGridView1.ColumnCount = 5 With dataGridView1.ColumnHeadersDefaultCellStyle .BackColor = Color.Navy .ForeColor = Color.White .Font = New Font(dataGridView1.Font, FontStyle.Bold) End With With dataGridView1 .EditMode = DataGridViewEditMode.EditOnEnter .Name = "dataGridView1" .Location = New Point(8, 8) .Size = New Size(500, 300) .AutoSizeRowsMode = _ DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders .ColumnHeadersBorderStyle = _ DataGridViewHeaderBorderStyle.Raised .CellBorderStyle = _ DataGridViewCellBorderStyle.Single .GridColor = SystemColors.ActiveBorder .RowHeadersVisible = False .Columns(0).Name = "Release Date" .Columns(1).Name = "Track" .Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter .Columns(2).Name = "Title" .Columns(3).Name = "Artist" .Columns(4).Name = "Album" ' Make the font italic for row four. .Columns(4).DefaultCellStyle.Font = _ New Font(Control.DefaultFont, _ FontStyle.Italic) .SelectionMode = _ DataGridViewSelectionMode.FullRowSelect .MultiSelect = False .BackgroundColor = Color.Honeydew .Dock = DockStyle.Fill End With End Sub
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: