C#DataGridView格式数字的问题

crecrecre 2009-01-12 02:04:22
在DataGridView里有一列是数字字段,如果该值是零,就不显示,或显示为空,如何设置?
0.00;0都不让它显示或为空。
...全文
222 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
delphi_911 2009-01-12
  • 打赏
  • 举报
回复
学习了。
python二级题库 2009-01-12
  • 打赏
  • 举报
回复
学习一下!!!
llsen 2009-01-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 libinguest 的回复:]
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
for (int i = 0; i < dataGridView1.RowCount;i++)
{
for(int j=1;j <4;j++)
if (dataGridView1.Rows[i].Cells[j].Value = 0)
{
dataGridView1.Rows[i].Cells[j].Value= "";

[/Quote]

if (Convert.ToInt32(dataGridView1.Rows[i].Cells[j].Value) == 0)
{
dataGridView1.Rows[i].Cells[j].Value= "";
}
hzhsky1985 2009-01-12
  • 打赏
  • 举报
回复
3楼的已经很简单啦,还有一种就是用datatable赋值,你的gridview就绑定这个datatable,这样你想怎么赋值都可以
crecrecre 2009-01-12
  • 打赏
  • 举报
回复
一定要这么麻烦?有没有简单一点的方法?
在VFP里format属性设为'Z'就行了,C#有没有这样的属性?
paking_wong 2009-01-12
  • 打赏
  • 举报
回复
有错误,这样才对
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
for (int i = 0; i < dataGridView1.RowCount;i++)
{
for(int j=1;j <4;j++)
if (dataGridView1.Rows[i].Cells[j].Value == "0" ||dataGridView1.Rows[i].Cells[j].Value == "0.00")
{
dataGridView1.Rows[i].Cells[j].Value= "";
}
}

}
风之影子 2009-01-12
  • 打赏
  • 举报
回复
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
for (int i = 0; i < dataGridView1.RowCount;i++)
{
for(int j=1;j <4;j++)
if (dataGridView1.Rows[i].Cells[j].Value = 0)
{
dataGridView1.Rows[i].Cells[j].Value= "";
}
}

}
结贴吧

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧