Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Dear All,
I have an datagridview with c# and each row in that gridview have status 0 or 1. So I want to change fore color of entire row that have status 1. How can I do it. Please help me. Thanks you all.
Posted

try this code

C#
for (int k = 0; k < grd1.RowCount; k++)
     {
         if (grd1.Rows[k].Cells["status"].Value.ToString()=="1")
         {
            grd1.Rows[k].DefaultCellStyle.BackColor = Color.LightBlue;
         }
      }
 
Share this answer
 
v2
if order of rows in the grid may changes, i suggest add this handler to grid CellPainting event
C#
private void ContentCellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex >= 0 && grid.Rows[e.RowIndex].Cells["Status"].Value.ToString() == "1")
    e.CellStyle.ForeColor = Color.Magenta;
else
    e.CellStyle.ForeColor = Color.GreenYellow;
}
 
Share this answer
 
v2

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