Change font color for certain rows in DataGridview

E

Elmo Watson

In ASP.Net, using a Gridview, you can conditionally set the forecolor of
each row (or column), based on certain criteria using the RowDataBound event

But I can't find an event that is similar in WinForms

I need to set the forecolor to red, if the the entry type (in column 1) is a
1 - -

How would I do this in a DataGridView?
 
E

Elmo Watson

Also forgot to mention - the column I'm using for the condition is invisible
 
C

ClayB

You can try using th eCellFormatting event.

void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
object val = dataGridView1["Col1", e.RowIndex].Value;
if (e.RowIndex > -1 && e.ColumnIndex >= -1
&& val != null && val.Equals(2))
{
e.CellStyle.BackColor = Color.Red;
}
}

====================
Clay Burch
Syncfusion, Inc.
 
N

nikhil soni

Thank you very much.it really help me to solve my Issue

Nikhil Soni
In ASP.Net, using a Gridview, you can conditionally set the forecolor of
each row (or column), based on certain criteria using the RowDataBound event

But I can't find an event that is similar in WinForms

I need to set the forecolor to red, if the the entry type (in column 1) is a
1 - -

How would I do this in a DataGridView?
On Friday, August 03, 2007 5:10 PM Elmo Watson wrote:
Also forgot to mention - the column I am using for the condition is invisible
On Friday, August 03, 2007 8:46 PM ClayB wrote:
You can try using th eCellFormatting event.

void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
object val = dataGridView1["Col1", e.RowIndex].Value;
if (e.RowIndex > -1 && e.ColumnIndex >= -1
&& val != null && val.Equals(2))
{
e.CellStyle.BackColor = Color.Red;
}
}

====================
Clay Burch
Syncfusion, Inc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top