DataGridView - how to set the currency format for a single column ONLY

前端 未结 2 1827
逝去的感伤
逝去的感伤 2020-12-09 23:44

I am trying to use the datagridview for a basket. I have got it to display the basket of the customer but I would like it to display the currency for the Price column, but i

相关标签:
2条回答
  • 2020-12-10 00:15

    You can set format of data of a column using Format property of its DefaultCellStyle property of the column.

    For example to use currency format for second column of a DataGridView using current culture, you can use such code:

    grid1.Columns[1].DefaultCellStyle.Format = "c";
    

    Or for example to use an specific culture and specific decimal numbers:

    grid1.Columns[1].DefaultCellStyle.Format = "c2";
    grid1.Columns[1].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("en-GB");
    

    More Information

    • How to: Format Data in the Windows Forms DataGridView Control
    • Standard Numeric Format Strings - The Currency ("C") Format Specifier.

    Note

    If you are using an object data source, then you can use the following approaches as well. The Foundation is same, setting suitable format for the column, but using attributes:

    • DataAnnotations attributes for DataGridView in Windows Forms
    • Using custom attributes to control appearance of DataGridView columns
    0 讨论(0)
  • 2020-12-10 00:21

    Create DataGridView columns at design time and sets the price only format the Current Price column Datagridview tutorial

    Set DateTime format in DataGridView This link is seen as setting the date format, just change the date format for the currency format.

    0 讨论(0)
提交回复
热议问题