DataGridViewAdvancedBorderStyle Class
Contains border styles for the cells in a DataGridView control.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The DataGridViewAdvancedBorderStyle type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | DataGridViewAdvancedBorderStyle | Initializes a new instance of the DataGridViewAdvancedBorderStyle class. |
| Name | Description | |
|---|---|---|
![]() | Equals | Determines whether the specified object is equal to the current DataGridViewAdvancedBorderStyle. (Overrides Object.Equals(Object).) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Overrides Object.GetHashCode().) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the DataGridViewAdvancedBorderStyle. (Overrides Object.ToString().) |
The DataGridView control allows you to fully customize its appearance, including the borders of the cells and headers. The DataGridView has CellBorderStyle, ColumnHeadersBorderStyle, and RowHeadersBorderStyle properties that allow you to set the appearance of the cell border. However, if you need to further customize the borders, the DataGridViewAdvancedBorderStyle class allows you to set the style of the border on the individual sides of the cells. The Left, Right, Top, and Bottom properties of DataGridViewAdvancedBorderStyle represent the left, right, top, and bottom border of a cell, respectively. You can set these properties on the AdvancedCellBorderStyle, AdvancedColumnHeadersBorderStyle, AdvancedRowHeadersBorderStyle properties of the DataGridView to produce various appearances for the borders between the cells.
The following code example adjusts the cell borders of a DataGridView so that a double border separates the interior cells and the top left header cell from the row and column headers. This sample demonstrates how to override the AdjustColumnHeaderBorderStyle, AdjustRowHeaderBorderStyle, and AdjustCellBorderStyle methods, and the AdjustedTopLeftHeaderBorderStyle property. These members use DataGridViewAdvancedBorderStyle objects to modify individual cell borders.
using System; using System.Drawing; using System.Windows.Forms; namespace DataGridViewAdvancedBorderStyleSample { class Form1 : Form { [STAThreadAttribute()] public static void Main() { Application.EnableVisualStyles(); Application.Run(new Form1()); } public Form1() { this.AutoSize = true; this.Controls.Add(new CustomDataGridView()); this.Text = "DataGridView advanced border styles demo"; } } public class CustomDataGridView : DataGridView { public CustomDataGridView() { this.RowTemplate = new DataGridViewCustomRow(); this.Columns.Add(new DataGridViewCustomColumn()); this.Columns.Add(new DataGridViewCustomColumn()); this.Columns.Add(new DataGridViewCustomColumn()); this.RowCount = 4; this.EnableHeadersVisualStyles = false; this.AutoSize = true; } public override DataGridViewAdvancedBorderStyle AdjustedTopLeftHeaderBorderStyle { get { DataGridViewAdvancedBorderStyle newStyle = new DataGridViewAdvancedBorderStyle(); newStyle.Top = DataGridViewAdvancedCellBorderStyle.None; newStyle.Left = DataGridViewAdvancedCellBorderStyle.None; newStyle.Bottom = DataGridViewAdvancedCellBorderStyle.Outset; newStyle.Right = DataGridViewAdvancedCellBorderStyle.OutsetDouble; return newStyle; } } public override DataGridViewAdvancedBorderStyle AdjustColumnHeaderBorderStyle( DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceHolder, bool firstDisplayedColumn, bool lastVisibleColumn) { // Customize the left border of the first column header and the // bottom border of all the column headers. Use the input style for // all other borders. dataGridViewAdvancedBorderStylePlaceHolder.Left = firstDisplayedColumn ? DataGridViewAdvancedCellBorderStyle.OutsetDouble : DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceHolder.Bottom = DataGridViewAdvancedCellBorderStyle.Single; dataGridViewAdvancedBorderStylePlaceHolder.Right = dataGridViewAdvancedBorderStyleInput.Right; dataGridViewAdvancedBorderStylePlaceHolder.Top = dataGridViewAdvancedBorderStyleInput.Top; return dataGridViewAdvancedBorderStylePlaceHolder; } } public class DataGridViewCustomColumn : DataGridViewColumn { public DataGridViewCustomColumn() { this.CellTemplate = new DataGridViewCustomCell(); } } public class DataGridViewCustomCell : DataGridViewTextBoxCell { public override DataGridViewAdvancedBorderStyle AdjustCellBorderStyle( DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceHolder, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool firstVisibleColumn, bool firstVisibleRow) { // Customize the top border of cells in the first row and the // right border of cells in the first column. Use the input style // for all other borders. dataGridViewAdvancedBorderStylePlaceHolder.Left = firstVisibleColumn ? DataGridViewAdvancedCellBorderStyle.OutsetDouble : DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceHolder.Top = firstVisibleRow ? DataGridViewAdvancedCellBorderStyle.InsetDouble : DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceHolder.Right = dataGridViewAdvancedBorderStyleInput.Right; dataGridViewAdvancedBorderStylePlaceHolder.Bottom = dataGridViewAdvancedBorderStyleInput.Bottom; return dataGridViewAdvancedBorderStylePlaceHolder; } } public class DataGridViewCustomRow : DataGridViewRow { public override DataGridViewAdvancedBorderStyle AdjustRowHeaderBorderStyle( DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceHolder, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedRow, bool isLastDisplayedRow) { // Customize the top border of the first row header and the // right border of all the row headers. Use the input style for // all other borders. dataGridViewAdvancedBorderStylePlaceHolder.Top = isFirstDisplayedRow ? DataGridViewAdvancedCellBorderStyle.InsetDouble : DataGridViewAdvancedCellBorderStyle.None; dataGridViewAdvancedBorderStylePlaceHolder.Right = DataGridViewAdvancedCellBorderStyle.OutsetDouble; dataGridViewAdvancedBorderStylePlaceHolder.Left = dataGridViewAdvancedBorderStyleInput.Left; dataGridViewAdvancedBorderStylePlaceHolder.Bottom = dataGridViewAdvancedBorderStyleInput.Bottom; return dataGridViewAdvancedBorderStylePlaceHolder; } } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
