首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

GataGridView中百分数输入的有关问题,C

2012-03-15 
GataGridView中百分数输入的问题,C#我想让GataGridView可以显示百分数,所以写了如下代码:C# codedataGridV

GataGridView中百分数输入的问题,C#
我想让GataGridView可以显示百分数,所以写了如下代码:

C# code
dataGridView1.Columns[9].DefaultCellStyle.Format = "#.00%";

现在想显示值“82.00%”,需要在GataGridView中输入“0.82”;
怎样做可以改为输入“82”后显示为“82.00%”?

还有就是点击进入显示着“82.00%”的单元格,想在“82.00%”前面加一个“2”,变成“282.00%”会报错,可能是不能接受“%”符号,这又该怎么办呢?

[解决办法]
不知道你列是什么属性,如果是integer,则无法实现。你新建个测试项目,新窗体,拖一个DataGridView,和一个按钮,按钮方法如下,可以看到你要的正确效果。
C# code
private void button1_Click(object sender, EventArgs e){    DataTable table = new DataTable();    table.TableName = "aa";    table.Columns.Add("test", typeof(float));    DataRow row = table.NewRow();    row[0] = 0.82;    table.Rows.Add(row);    dataGridView1.DefaultCellStyle.Format = "#.00%";    dataGridView1.DataSource = table;}
[解决办法]
只有FLOAT型才可以

热点排行