We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Change Font Color of Rows

Hi,

I would want to change the Font Color of Specific rows depending on some condition, The code I am using is as follows :

private void dgrdCato_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
if (e.RowIndex > 0)
{
if (dgrdCato[e.RowIndex, 6].Text.ToString().Equals("Active"))
e.Style.TextColor = Color.Green;
else
e.Style.TextColor = Color.Red;
dgrdCato.RefreshRange(GridRangeInfo.Row(e.RowIndex));
}
}

However the above is not working, kindly help.

1 Reply

RA Rajagopal Syncfusion Team June 22, 2007 05:33 PM UTC

Hi Raul,

You need to catch the PrepareViewStyleInfo event of the grid to do this. In the event handler, you need to check your condition based on e.RowIndex and e.ColIndex, and then conditionally set e.Style.TextColor.

void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
if (e.RowIndex > 0 && e.ColIndex > 0)
{
if (e.Style.Text == "Active")
e.Style.TextColor = Color.Green;
else
e.Style.TextColor = Color.Red;
}
}

Let us know if you need any further help.
Regards,
Rajagopal

Loader.
Live Chat Icon For mobile
Up arrow icon