Click here to Skip to main content
14,774,521 members
Please Sign up or sign in to vote.
4.11/5 (2 votes)
Greetings.

My problem is I want to change the font color of the cell in the datagridview, not the entire row, and I want to do it programmatically, any suggestions that might help ?

Thanks.
Posted
Updated 24-Feb-15 15:53pm
v2

   
Comments
Lloydii 3-Mar-15 2:01am
   
Thank you ! Its working
Peter Leow 3-Mar-15 6:00am
   
You are welcome.
dataGridView1.RowsDefaultCellStyle.BackColor = Color.Red;
   
v2
Comments
CHill60 5-May-15 9:55am
   
That will change the BackColor not the font color (ForeColor)
Real_Criffer 5-May-15 21:06pm
   
awwww ><' so just change it to forecolor then thank for you advice ^^
On RowDataBound(object sender, GridViewRowEventArgs e) event use code

e.Row.Cells[9].BackColor =System.Drawing.Color.Orange;

and For Font color

e.Row.Cells[9].ForeColor = System.Drawing.Color.Black;
   
We can change the font color of perticular cell text in grid view using the rowdatabound event..

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

if (e.Row.Cells[1].Text == "ECE")

{

// change the color

e.Row.Cells[1].ForeColor = System.Drawing.Color.Green;

}

}

}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900