Show empty cell if value in currency is 0

4 posts, 0 answers
  1. Uwe
    Uwe avatar
    3 posts
    Member since:
    Mar 2020

    Posted 04 Apr Link to this post

     

    Is it possibly to suppress the 0.00 value and show just a empty cell.

    That's because i've a grid with lot of currency values and it's mostly better just to see cells with values != 0.

     

    RadGridView1.Columns.Add(New GridViewDecimalColumn("Currency"))  
    RadGridView1.Columns(0).FormatString = "{0:C}"

  2. Nadya
    Admin
    Nadya avatar
    344 posts

    Posted 08 Apr Link to this post

    Hello Uwe,

    Yes, it is possible to achieve this. You can use the CellFormatting event to change the text of the cell if its value is 0:

    private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
           {
                if (e.Column is GridViewDecimalColumn && e.CellElement.Value != null)
                {
                    var value = (decimal)e.CellElement.Value;
                    if (value == 0)
                    {
                        e.CellElement.Text = "";
                    }
                }
           }

    I hope this helps. Should you have other questions I will be glad to help.

    Regards,
    Nadya
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  3. Uwe
    Uwe avatar
    3 posts
    Member since:
    Mar 2020

    Posted 08 Apr in reply to Nadya Link to this post

    That's obviously the first idea, but i hoped you had a better one. And you do, as i found recently:

              var obj = new ExpressionFormattingObject("Condition_" + colName, colName + " = 0", true) {CellForeColor = Color.Transparent};
              this.Grid.Columns[colName].ConditionalFormattingObjectList.Add(obj);

  4. Nadya
    Admin
    Nadya avatar
    344 posts

    Posted 08 Apr Link to this post

    Hello Uwe,

    I am glad that you managed to find another solution to achieve your goal. Thank you for sharing it with the community. Feel free to use this one that suits your requirements the best.

    Should you have other questions do not hesitate to ask.

    Regards,
    Nadya
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top