-1

I have a DataGridView object on my form that is linked to a dataTable populated based on a variable SQL query.
My problem comes with the way that negative values are displayed with the .DefaultCellStyle.Format value set to "c" for currency. For some reason, it places negative values within parenthesis, i.e. (100 000) instead of - 100 000

I use :

dgvprod.Columns[2].DefaultCellStyle.Format = "c0";
dgvprod.Columns[2].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("fr-SN");

and Its displays by exemple (400 000) rather than -400 000
someone could help me to change it please ?
thank you in advance

  • What is the datatable content? Type? – TaW Oct 05 '18 at 14:24
  • @TaW these are strings –  Oct 05 '18 at 14:30
  • But "C0" is a number format. You can't format string like that. You would have to convert to numbers first. But how are they stored in the sql? How did they become strings?? – TaW Oct 05 '18 at 14:33
  • @TaW there are several columns but the column2 is stored as int in the database –  Oct 05 '18 at 14:34
  • Then your sql is the culprit? – TaW Oct 05 '18 at 14:38
  • what do you mean? My problem comes with the way that negative values are displayed with the .DefaultCellStyle.Format value set to "c" for currency. For some reason, it places negative values within parenthesis, i.e. ($2250.45) instead of -$2250.45 –  Oct 05 '18 at 14:38
  • @Kevin - can you please tell what is your result in gridview without setting format and culture info. Then it might lead us to the cause which is giving this problem. – ANaik Oct 05 '18 at 14:48
  • without setting format , its returns 4 datas - two string and 3 ints , by example MARC | ARN | 40000 | 400000 | 400000 –  Oct 05 '18 at 14:53

1 Answers1

1

Try the format

"#,0 CFA;-#,0 CFA"

The first section applies to 0 and positive values, the second to negative values.

Or simply

"#,0 CFA"

But the result depends on the specific culture and culture settings in Windows. The value must be of a numeric type. If it is a string, it cannot be formatted.

See also: Custom numeric format strings

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188