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

How to color code a negative number

[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; }
    set
    {

        m_grid.M_DataSource - value;

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

        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;

        m_grid.Show();
    }
}

 

Thanks

Vaibhav


2 Replies

VS Vaibhav Sanghavi December 10, 2012 10:01 AM UTC

Just to clarify.. this is a GridDataboundGrid



VK Vinish Kumar K Syncfusion Team December 19, 2012 02:27 AM UTC

Hi Vaibhav Sanghavi

 

Thank you for your interested in Syncfusion products.

 

Query

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.

 

Code:

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.

 

Regards,

Vinish.


Loader.
Live Chat Icon For mobile
Up arrow icon