Click here to Skip to main content
15,888,076 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
changing the color of the cell when it finds values in the range of hundred in datagrid view
Posted
Comments
Member 8983639 25-May-12 2:38am    
any one give a sample for this pls

1 solution

Create a handler for the CellValueChanged event, something like this.

C#
protected override void OnCellValueChanged(DataGridViewCellEventArgs e)
{
    base.OnCellValueChanged(e);

    // Test value of cell which just changed
    if (uint.Parse(this.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()) == 100)
    {
        // Cell value is now 100 - make cell background red
        this.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = System.Drawing.Color.Red;
    }
    else
    {
        // Cell value is not 100 - make background white
        this.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = System.Drawing.Color.White;
    }
}
 
Share this answer
 
Comments
Prasad_Kulkarni 25-May-12 9:07am    
Good answer, but I must say it is incomplete. OP requested for the range of hundred and your answer works only for 100. Make appropriate corrections, it will work. (4) for your answer.
Zasky 25-May-12 9:32am    
Fair enough, but as it's not clear what 'the range of hundred' means I went for the simplest solution. A range of a hundred doesn't indicate the upper and lower bounds. Okay, it probably meant 0-100, but I'm sure OP can handle a condition statement.

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