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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to color code a negative number

Thread ID:





106087 Dec 10,2012 10:00 AM UTC Dec 19,2012 02:27 AM UTC WinForms 2
Tags: GridControl
Vaibhav Sanghavi
Asked On December 10, 2012 10:00 AM UTC

[Apologies as I am posting a WinFrom C# quetion in ASP.NET as the WinForm link is down]

I am trying to add RED color to a column if the vaule is negative. Its a currency field. Even though the code gets compiled and executed fine it simply doesn't have any effect on UI. Could you help me understand whats worng with the code..

public DataView M_Grid_DataSource
    get { return m_grid.M_DataSource as DataView; }

        m_grid.M_DataSource - value;

        int ind = m_grid.NameToColIndex("FieldName");

        GridStyleInfo style = new GridStyleInfo();
        style.CellType = "Currency";
        style.CurrencyEdit.CurrencyNegativePattern = 0;
        style.CurrencyEdit.NegativeColor = Color.Red

        GridBoundColumnsCollection collection = m_grid.GridBoundColumns;
        GridBoundColumn n = collection[ind];
        n.StyleInfo = style;





Vaibhav Sanghavi
Replied On December 10, 2012 10:01 AM UTC

Just to clarify.. this is a GridDataboundGrid

Vinish Kumar K [Syncfusion]
Replied On December 19, 2012 02:27 AM UTC

Hi Vaibhav Sanghavi


Thank you for your interested in Syncfusion products.



Set recolor for negative number

Yes, you can achieve this using QueryCellInfo event. Set the backcolor for this using the following codes in QueryCellInfo event.



private void gridControl1_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)


double i = 0;

if (Double.TryParse(e.Style.FormattedText, out i) && i < 0)


e.Style.TextColor = Color.Red;




Please implement this codes in your application. and let me know if this works for you.




Please let me know if you have further concerns.





This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon