This is a migrated thread and some comments may be shown as answers.

Show empty cell if value in currency is 0

3 Answers 135 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Uwe
Top achievements
Rank 1
Uwe asked on 04 Apr 2020, 01:57 PM

 

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}"

3 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 08 Apr 2020, 11:22 AM

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.
0
Uwe
Top achievements
Rank 1
answered on 08 Apr 2020, 01:40 PM

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);

0
Nadya | Tech Support Engineer
Telerik team
answered on 09 Apr 2020, 04:35 AM

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.
Tags
GridView
Asked by
Uwe
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Uwe
Top achievements
Rank 1
Share this question
or