Click here to Skip to main content
14,826,929 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:

My subject itself tells my issue..What I need is that I want to change my Cell Background Color or Foreground Color in my Datagrid depends on my value in the cell..But here my value is not hard-coded, it will change dynamically ( 15.56 or 25.30 or some double values )..

Note :

I googled for a solution but i got only static value cell color change solution..Please help me to find solution for this issue..

lukeer 5-Jul-12 5:02am
Post the static value cell color change solution that you tried. Maybe we can combine it with some ValueChanged event.

Use the "Improve question" link for that.
Ahn_7 5-Jul-12 5:10am
For static value cell color change..Refer this Link

It's very simple. You can either loop through cells or directly set it like below.

this.dataGridView1.Rows[0].Cells[1].Style.ForeColor = System.Drawing.Color.Red;

If you wan't it to happen dynamically, code the below event. For example

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    if (e.ColumnIndex == 0 && e.RowIndex == 0)
        e.CellStyle.ForeColor = Color.Red;
Ahn_7 5-Jul-12 6:41am
I'm using WPF..So please suggest me a solution regarding WPF..[^]

Take look of above example see marked answer. It will definately work for you.
This will solve your issue

Mark as solution if it works for you....

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