0
我有一个datagridview以货币格式显示我的记录。我设置DefaultCellStyle属性永久为格式但是我有一个特定的列,我想要显示它的值作为一个整数。如何更改特定的datagridview列格式
的专栏中,我想改变它显示的内容:
[AreaCode]
15,00 €
25,00 €
60,00 €
我的期望:
[AreaCode]
15
25
60
这里是我的代码是不工作:
private void dgv1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
var columnname = "AreaCode";
if (e.ColumnIndex == dgv1.Columns[columnname].Index)
{
//Get the datagridview cell
DataGridViewCell cell = dgv1.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (cell != null)
{
this.dgv1.Columns["AreaCode"].DefaultCellStyle.Format = "D4";
}
}
}
日Thnx提前
怎么样'D2'而不是? 'D4'使您的值为'0015','0025'和'0060'。 – 2015-04-02 11:04:37
嗨 听起来不错,但我的代码有问题。错误: 未将对象引用设置为对象实例。 – mikybrain 2015-04-02 11:18:35
阅读:[什么是'NullReferenceException',我该如何解决它?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it ) – 2015-04-02 11:26:39