【问题标题】:add value if cell null c# dataGridView如果单元格为空,则添加值 c# dataGridView
【发布时间】:2018-05-20 05:26:26
【问题描述】:

[C# winform] 如果单元格为空,我想将值放入 DataGridView 的单元格中,帮帮我

enter image description here

【问题讨论】:

  • 到目前为止你做了什么?
  • 我不明白你的意思,我刚加入
  • 向我们展示你到目前为止所做的代码,否则我们很难为你提供帮助。
  • for(int i = 0; i
  • 运行该代码 sn-p 会发生什么?

标签: c# winforms datagridview


【解决方案1】:

直接取自有关您问题的 cmets,但格式可读:

for(int i = 0; i < dgv.Rows.Count; i++)
{
    for(int j = 0; j < dgv.Columns.Count; j++)
    {
        if (dgv.Rows[i].Cells[j].Value == null)
        {
            dgv.Rows[i].Cells[j].Value = "0";
        }
    }
}

我认为没有任何原因不起作用,如果确实有效,请让人们知道,以便将来遇到类似问题的人可以使用它。

我建议将dgv.Rows[i].Cells[j].Value == null 更改为string.IsNullOrEmpty(dgv.Rows[i].Cells[j].Value),它确保值永远不会是"",它不为空但会显示为空。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 2021-12-06
    • 1970-01-01
    相关资源
    最近更新 更多