datagridview单元格中为空,空白问题
datagridview在取值计算前在循环中加入判断,如果单元格中没有填入值,就程序写入"0"if(this.dataGridView1.Rows[j].Cells[5]...
datagridview在取值计算前在循环中加入判断,如果单元格中没有填入值,就程序写入"0"
if (this.dataGridView1.Rows[j].Cells[5].Value != null
||this.dataGridView1.Rows[j].Cells[5].Value.ToString() != string.Empty
|| this.dataGridView1.Rows[j].Cells[5].Value != "")
{
battle_price = dataGridView1.Rows[j].Cells[5].Value.ToString();
}
else
{
dataGridView1.Rows[j].Cells[5].Value = temp; // temp=0
battle_price = "0";
}
上面判断无法实现,空的还是直接赋值成了"" 展开
if (this.dataGridView1.Rows[j].Cells[5].Value != null
||this.dataGridView1.Rows[j].Cells[5].Value.ToString() != string.Empty
|| this.dataGridView1.Rows[j].Cells[5].Value != "")
{
battle_price = dataGridView1.Rows[j].Cells[5].Value.ToString();
}
else
{
dataGridView1.Rows[j].Cells[5].Value = temp; // temp=0
battle_price = "0";
}
上面判断无法实现,空的还是直接赋值成了"" 展开
3个回答
展开全部
你的if判断有问题,你取出来的数据如果是“”那么它就!=null执行第一个,如果是null,那么它就!=“”仍然执行第一个。把||改成&&试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
循环遍历所有单元格,然后在判断。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if (!string.IsNullOrEmpty(this.dataGridView1.Rows[j].Cells[5].Value.Trim()))
{
........
}
else
{
.................
}
{
........
}
else
{
.................
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询