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

Red text for negative values in cells

G''day,

I need to be able to set a format for numbers (for a cell in a grid) so that when the cell contains a negative value, the number will show up red. Is this possible?

Cheers,
TERRY

4 Replies

AD Administrator Syncfusion Team August 21, 2006 05:01 AM UTC

Hi Terry,

If you use a CurrencyEdit celltype, you can use style.CurrencyEdit.NegativeColor to set this color. But if you are using other celltypes, then you would have to handle PrepareViewStyleInfo event to dynamically change the textcolor. Here is some code snippet.

private void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
double d;
if(e.RowIndex > 0 && e.ColIndex == 2
&& double.TryParse(e.Style.Text, System.Globalization.NumberStyles.Any, null, out d)
&& d < 0)
{
e.Style.TextColor = Color.Red;
}
}

Thanks for using Syncfusion Products.
Regards,
Rajagopal


RA Robert Avery October 18, 2010 10:02 PM UTC

Is this still the only way to color the text red if the number is negative? Thanks.



NR Nirmal Raja Syncfusion Team November 2, 2010 10:44 AM UTC

Hi Robert,

This is the best way to provide color to the cell conditionally, which gets updated dynamically on any changes in the grid description. The GridGroupingControl can have the Conditional Format, which helps the row to be in certain color which is related to the condition.

Please let me know if you find any issue with this way of achieving the behavior, so that we can look into the specific perpective and provide you a fixed sample.

Let me know if you have any concern.

Regards,
Nirmal



NR Nirmal Raja Syncfusion Team November 2, 2010 10:45 AM UTC

Hi Robert,

This is the best way to provide color to the cell conditionally, which gets updated dynamically on any changes in the grid description. The GridGroupingControl can have the Conditional Format, which helps the row to be in certain color which is related to the condition.

Please let me know if you find any issue with this way of achieving the behavior, so that we can look into the specific perpective and provide you a fixed sample.

Let me know if you have any concern.

Regards,
Nirmal


Loader.
Live Chat Icon For mobile
Up arrow icon