Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have one data-grid view which is bind dynamically. and it contain data like below screen shot.

Image Link
http://i.stack.imgur.com/RZOSN.jpg[^]

Now problem is i want change cell color based on data value. i want to deduct tamount-paymentamont and if it >=1 then i want to set this two cell color as a red and other as green.at every new data bind.
Posted
Updated 18-Sep-13 20:48pm
v2

1 solution

i try this and it work for me..

C#
for (int n = 0; n < (dataGridView1.Rows.Count - 1); n++)
                {
                    double i = Convert.ToDouble(dataGridView1.Rows[n].Cells["tamount"].Value.ToString().Replace('.', ','));
                    double j = Convert.ToDouble(dataGridView1.Rows[n].Cells["paymentamount"].Value.ToString().Replace('.', ','));
                    double total = i - j;
                    if (total >= 1)
                    {
                        dataGridView1.Rows[n].Cells["tamount"].Style.BackColor = Color.LightPink;
                        dataGridView1.Rows[n].Cells["paymentamount"].Style.BackColor = Color.LightPink;

                    }
                    else
                    {
                        dataGridView1.Rows[n].Cells["tamount"].Style.BackColor = Color.LightGreen;
                        dataGridView1.Rows[n].Cells["paymentamount"].Style.BackColor = Color.LightGreen;
                    }

                }
 
Share this answer
 

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