Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to change the color to green when checkbox column cell value is checked(Selected/Ticked) and to red if its not(Selected/Ticked)

how can i do this?

What I have tried:

datagridview1.Rows[e.rowindex].Columns[e.columnindex].Style=color.green;
Posted
Updated 10-May-19 21:02pm

Something like this:
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
    if (e.ColumnIndex == 4)
    {
        var check = myDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;

        if (check == null) return;

        if ((bool)check == true)
        {
            dataGridView1[e.ColumnIndex, e.RowIndex].Style.ForeColor = Color.Green;
        }
        else
        {
            dataGridView1[e.ColumnIndex, e.RowIndex].Style.ForeColor = Color.Red;
        }
    }

}
 
Share this answer
 
v2
Something like this:
private void myDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (e.ColumnIndex == 4)
    {
        var check = myDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;

        if (check == null) return;

        if ((bool)check == true)
        {
            e.CellStyle.ForeColor = Color.Green;
        }
        else
        {
            e.CellStyle.ForeColor = Color.Red;
        }
    }
}
 
Share this answer
 
Comments
Member 12899279 12-May-19 16:33pm    
thanks but i want to change the color of tick mark only to green when its checked and to red when its unchecked.
not the whole row just the TICK mark to 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