Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change color of a column in datagridview?

I have a DataGridview, and I'm setting some of the columns to readonly for data entry purposes. When I do that, the column stays the normal white (although it does not allow entry). How can I color the column gray? I've seen lots of samples on how to color rows, but not columns.

How can I make the readonly columns look gray?

like image 339
MAW74656 Avatar asked Sep 20 '11 20:09

MAW74656


People also ask

How to change Grid column color in c#?

BackColor = Color. Azure or = Color. FromArgb(51, 102, 153); which I prefer using cause it can adjust how light or dark the color is.

Which property is used in Windows desktop application form to set font color?

DefaultCellStyle property to set these styles for the entire control.


3 Answers

Try setting the DefaultCellStyle property for the selected columns.

Edit:

grid.Columns["NameOfColumn"].DefaultCellStyle.ForeColor = Color.Gray;
like image 99
Krishna Avatar answered Oct 24 '22 10:10

Krishna


just change the style for the DataGridViewColumn object,

myGrid.Columns["myColumn"].DefaultCellStyle.BackColor = Color.Red;
like image 39
Davide Piras Avatar answered Oct 24 '22 09:10

Davide Piras


You can specify the cell background colours for a column like so using the DefaultCellStyle property of a DataGridViewColumn.

DataGridView1.Columns[0].DefaultCellStyle.BackColor = Color.Gray;
like image 4
jdavies Avatar answered Oct 24 '22 09:10

jdavies