Hadi Khodayari
Hadi Khodayari

Reputation: 31

don't show zero ("0") in datagridview cell in c#

I used string.format() for a column in datagridview to separate thousands with comma but

in cases that the value is zero "0" the datagridview's cell don't show zero and cell is empty

dataGridView2.Columns[7].ValueType = typeof(string);

dataGridView2.Columns[7].DefaultCellStyle.Format = string.Format("#,#", System.Globalization.CultureInfo.InvariantCulture) ;

please help me

regards

Upvotes: 0

Views: 4741

Answers (1)

Daniel Gimenez
Daniel Gimenez

Reputation: 20544

From MSDN:Custom Numeric Format Strings

  • # Never displays zero if it is not a significant digit.
  • 0 means a digit and display 0 if nothing is present.

So I changed the expression to #,0, and it worked:

  • 0.0 => 0
  • 50.0 => 50
  • 74.0 => 74
  • 1260.0 => 1,260
  • 12325.0 => 12,325

Upvotes: 1

Related Questions