Permalink
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (58 sloc) 5.33 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
How to: Change the Border and Gridline Styles in the Windows Forms DataGridView Control
03/30/2017
.net-framework
dotnet-winforms
article
jsharp
gridlines, changing styles
data grids, changing gridline styles
DataGridView control [Windows Forms], border styles
data grids, changing border styles
DataGridView control [Windows Forms], gridline styles
2f413c7a-4025-4171-8e3a-66ef908ea583
15
dotnet-bot
dotnetcontent
wpickett

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

With the xref:System.Windows.Forms.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 xref:System.Windows.Forms.DataGridViewCellBorderStyle.Single, xref:System.Windows.Forms.DataGridViewCellBorderStyle.SingleHorizontal, and xref:System.Windows.Forms.DataGridViewCellBorderStyle.SingleVertical values of the xref:System.Windows.Forms.DataGridViewCellBorderStyle enumeration and the xref:System.Windows.Forms.DataGridViewHeaderBorderStyle.Single value of the xref:System.Windows.Forms.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 xref:System.Windows.Forms.Application.EnableVisualStyles%2A?displayProperty=nameWithType method, the xref:System.Windows.Forms.DataGridView.GridColor%2A property value is not used.

To change the gridline color programmatically

To change the border style of the entire DataGridView control programmatically

To change the border styles for DataGridView cells programmatically

Example

[!code-csharpSystem.Windows.Forms.DataGridViewMisc#030] [!code-vbSystem.Windows.Forms.DataGridViewMisc#030]

Compiling the Code

This example requires:

  • A xref:System.Windows.Forms.DataGridView control named dataGridView1.

  • References to the xref:System?displayProperty=nameWithType, xref:System.Windows.Forms?displayProperty=nameWithType, and xref:System.Drawing?displayProperty=nameWithType assemblies.

See Also

xref:System.Windows.Forms.BorderStyle
xref:System.Windows.Forms.DataGridView.BorderStyle%2A?displayProperty=nameWithType
xref:System.Windows.Forms.DataGridView.CellBorderStyle%2A?displayProperty=nameWithType
xref:System.Windows.Forms.DataGridView.ColumnHeadersBorderStyle%2A?displayProperty=nameWithType
xref:System.Windows.Forms.DataGridView.GridColor%2A?displayProperty=nameWithType
xref:System.Windows.Forms.DataGridView.RowHeadersBorderStyle%2A?displayProperty=nameWithType
xref:System.Windows.Forms.DataGridViewCellBorderStyle
xref:System.Windows.Forms.DataGridViewHeaderBorderStyle
Basic Formatting and Styling in the Windows Forms DataGridView Control