Click here to Skip to main content
15,881,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DataGridView with two Columns. The default fore color is black. I want to change the fore color of the cell which has a minus value. How can i achieve this?

TotalQty | TotalAmount
---------------------
10 | 10000
-10 | -1000
-12 | -2000
20 | 12000


Thanks!
Posted

1 solution

Try this
C#
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    // If the column is the Artist column, check the
    // value.
    if (this.dataGridView1.Columns[e.ColumnIndex].Name == "yourColumnName")
    {
        if (e.Value != null)
        {
            // Check for the string "pink" in the cell.
            int Value = e.Value;
            if (Value<0))
            {
                e.CellStyle.BackColor = Color.Pink;
            }

        }
    }

}

Hope this helps
 
Share this answer
 
Comments
zoozjar 4-Feb-13 1:50am    
This is helpful for me. I got it. Thanks a lot! :)

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