Reza Paidar
Reza Paidar

Reputation: 883

how to change background color of a grid view cell in windows forms by C#

I have a filled grid view from a dataset; i want to check Column[4] cells (except header) that if it's cell's value less that 0 , it's background change to red .

please help ... Thanks alot

Upvotes: 1

Views: 4928

Answers (2)

Abhishek Jaiswal
Abhishek Jaiswal

Reputation: 1249

Go in commonHeaderCellStyle property as set as you want.

Upvotes: 0

Flipbed
Flipbed

Reputation: 720

Here is an example that works in windows forms.

        dataGridView1.Rows.Add(3, 2, -3);
        dataGridView1.Rows.Add(1, -2, 3);

        foreach (DataGridViewRow row in dataGridView1.Rows) 
        {
            if (!row.IsNewRow && int.Parse(row.Cells[2].Value.ToString()) < 0)
                row.Cells[2].Style.BackColor = Color.Red;
        }

Upvotes: 3

Related Questions