articles

Home / DeveloperSection / Articles / Datagridview Formatting in C#

Datagridview Formatting in C#

Vijay Shukla 10645 23-Jun-2013

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
 private void Form1_Load(object sender, EventArgs e)

 {
 dataGridView1.RowsDefaultCellStyle.BackColor = Color.AliceBlue;
 dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Aqua;
 dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
 dataGridView1.DefaultCellStyle.SelectionBackColor = Color.CadetBlue;
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.White;
 dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
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#

 


c# c# 
Updated 07-Sep-2019

Leave Comment

Comments

Liked By