Click here to Skip to main content
15,902,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
how to change the color in datagridview row when i check the check box in C# windows applications?i have code for select one check box is in header column in datagridview it checks all check boxes and changing background color in a datagridview rows but i want when check one check box and corresponding datagridview row will change color

please help me

What I have tried:

C#
void ckBox_CheckedChanged(object sender, EventArgs e)
    {
        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
            DataGridViewCheckBoxCell check = row.Cells["Chk"] as   DataGridViewCheckBoxCell;
            if (Convert.ToBoolean(check.Value) == true)
                row.DefaultCellStyle.BackColor = Color.Wheat;
            else
                row.DefaultCellStyle.BackColor = Color.White;
        }
        this.dataGridView1.EndEdit();
    }
Posted
Updated 23-Feb-16 4:47am
v3

Handle CellContentClick event, check that checkbox cell is clicked and change DefaultRowStyle

C#
 Private void dgv_CellContentClick(object sende,DataGridViewCellEventArgs e) {
// check the field value that you need...

dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FireBrick;
dgv.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.White;
}
 
Share this answer
 
DatagridView1[_ColumnIndex, _RowIndex].Style.BackColor =color.White;
Here _ColumnIndex & _rowIndex are column number& row numbers respectively, which you want to change the color.
 
Share this answer
 

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