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.
Unfortunately, activation email could not send to your email. Please try again.

How to color code a negative number

Thread ID:





106087 Dec 10,2012 05:00 AM Dec 18,2012 09:27 PM Windows Forms 2
Tags: GridControl
Vaibhav Sanghavi
Asked On December 10, 2012 05:00 AM

[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 05:01 AM

Just to clarify.. this is a GridDataboundGrid

Vinish Kumar K [Syncfusion]
Replied On December 18, 2012 09:27 PM

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.

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.