Search This Blog

Sunday, March 30, 2014

Change the Border and Gridline Styles in the Windows Forms DataGridView Control

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.

To change the gridline color programmatically

  • Set the GridColor property.
this.dataGridView1.GridColor = Color.Blue;

To change the border style of the entire DataGridView control programmatically

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

To change the border styles for DataGridView cells programmatically

  • Set the CellBorderStyleRowHeadersBorderStyle, and ColumnHeadersBorderStyle properties.
this.dataGridView1.CellBorderStyle =
    DataGridViewCellBorderStyle.None;
this.dataGridView1.RowHeadersBorderStyle =
    DataGridViewHeaderBorderStyle.Single;
this.dataGridView1.ColumnHeadersBorderStyle =
    DataGridViewHeaderBorderStyle.Single;

No comments:

Post a Comment