Click here to Skip to main content
12,348,726 members (59,118 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
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 3-Feb-13 17:54pm
zoozjar1.4K

1 solution

Rate this: bad
 
good
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
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100