Change font color for certain rows in DataGridview

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
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?
 
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.
 
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.
 
Back
Top