Click here to Skip to main content
15,886,075 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear sir,
i want to change the color of a datagridviewrow where a datagridviewcheckboxcell is unchecked. plz help. i use c#.net

What I have tried:

C#
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
         {
             bool b;

             if (dataGridView1.Columns[0].Name == "*")
             {
                 for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                 {
                     b = Convert.ToBoolean(dataGridView1.Rows[i].Cells["*"].Value.ToString());
                     if(b==false)
                     {
                         dataGridView1.Rows[i].DefaultCellStyle.BackColor=Color.Red;
                     }
                 }
}
Posted
Updated 6-Apr-16 21:40pm
v2

1 solution

use CellContentClick Event

C#
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
      {
          if (dataGridView1.Columns[e.ColumnIndex].Name == "*")
          {
              bool flag = (bool)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue;
              if (flag)
                  dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
              else
                  dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
          }


      }
 
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