Search code examples
c#mysqldatagridviewcultureinfodatagridviewcolumn

Displaying negative values in a DataGridView without parentheses


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


Solution

  • 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