Home > DeveloperSection > Articles > Datagridview Formatting in C#

Datagridview Formatting in C#


C# C# 
Ratings:
0 Comment(s)
 5708  View(s)
Rate this:

Datagridview Formatting in C#

In this article I am trying to explain how to change the formatting of datagridview in C#.

The DataGridView control is extremely configurable and extensible; DataGridView provides many properties, methods, and events to modify its look and behavior. The DataGridView control makes it simple to define the basic appearance of cells and the display formatting of cell values. Below I write few line of code for formatting DataGridView appearance in C#.

Write the below code for change your DataGridView appearance

1.  private void Form1_Load(object sender, EventArgs e)

2.  {

3.  dataGridView1.RowsDefaultCellStyle.BackColor = Color.AliceBlue;

4.  dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Aqua;

5.  dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;

6.  dataGridView1.DefaultCellStyle.SelectionBackColor = Color.CadetBlue;

7.  dataGridView1.DefaultCellStyle.SelectionForeColor = Color.White;

8.  dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

9.  }

Code description:

1.       This is the Form1_Load event.

3.       Here set the default rows back color.

4.       Here set the alternative row back color.

5.       Here set the datagridview cell border none.

6.       Here set the datagridview selected row back color.

7.       Here set the datagridview selected row forecolor.

8.       Here when I click any cell entire row will selected.

Output: -

Datagridview Formatting in C#

 


Don't want to miss updates? Please click the below button!

Follow MindStick