Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Font Color of a Column in a DataGridView Control (C# winforms)

Tags:

c#

I have a DataGridView control with two columns. The default color of the text is black. Is it possible to set the fore color of the entire second row to gray?(or any other color)..

    COLUMN1 | COLUMN2
    -----------------
     black  | gray
     black  | gray
     black  | gray

Please help.. thanks.

like image 991
yonan2236 Avatar asked Aug 17 '10 01:08

yonan2236


People also ask

How to change font in DataGridView c#?

In winform datagrid, right click to view its properties. It has a property called DefaultCellStyle. Click the ellipsis on DefaultCellStyle, then it will present Cell Style Builder window which has the option to change the font size.

What is DataGridView in C#?

The DataGridView control provides a customizable table for displaying data. The DataGridView class allows customization of cells, rows, columns, and borders through the use of properties such as DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle, and GridColor.

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

DefaultCellStyle property to set these styles for the entire control.


2 Answers

Your subject and question are confusing, one refers to the column and one to the rows but anyway.

grid.Columns[1].DefaultCellStyle.ForeColor = Color.Gray;

should handle the column color.

grid.Rows[1].DefaultCellStyle.ForeColor = Color.Gray;

should handle the row color.

like image 56
Gary Avatar answered Sep 28 '22 02:09

Gary


dgv.Rows[1].DefaultCellStyle.ForeColor = Color.Gray;

or Columns[1], if that's what you meant.

like image 39
Jonathan Avatar answered Sep 28 '22 02:09

Jonathan