简体   繁体   English

c#Datagridview单元格不接受货币格式更改

[英]c# Datagridview cell not accepting currency format change

I am trying to change the format of a cell in a datagridview using the following code. 我正在尝试使用以下代码更改datagridview中单元格的格式。

        this.dataGridView[2, 1].ValueType = typeof(decimal);
        this.dataGridView[2, 1].Value = 500;
        this.dataGridView[2, 1].Style.BackColor = System.Drawing.Color.OrangeRed;
        this.dataGridView[2, 1].Style.Format = "c";

The colour of the cell changes but it doesnt not show in currency format. 单元格的颜色会更改,但不会以货币格式显示。

Anyone know why? 有人知道为什么吗?

Are you ensuring that the value assigned to .Value is numeric? 您是否确保分配给.Value的值是数字? (ie not a string) (即不是字符串)

In the examples I've seen, the "c" format is lowercased. 在我看到的示例中,“ c”格式为小写。 You may not need the "2" either. 您可能也不需要“ 2”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM