日期:2014-05-18  浏览次数:21570 次

有关C#中的DataGridView列显示小数位问题
条件:
1、用的是VS2005 C#设计的C/S结构的程式。

2、用数据邦定DataGridView控件,现后台数据库表中某字段是4小数位,结果DataGridView控件当前列就显示4位小数

要求:DataGridView控件当前列只显示用户录入的小数,即如下显示数:
13.0000 --> 13
14.5000 --> 14.5
23.7890 --> 23.789
34.3439 --> 34.3439

------解决方案--------------------
C# code

        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == 1)//改成你的列索引
            {
                e.CellStyle.Format = "0.####";
            }
        }

------解决方案--------------------
this.Column1.DefaultCellStyle.Format="0.####";
------解决方案--------------------
这东西更多的说明
http://msdn.microsoft.com/zh-cn/f9x2790s(vs.85).aspx