Click here to Skip to main content
14,661,075 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 2

Try this
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
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100