繁体   English   中英

System.InvalidOperationException,同时检查空值

[英]System.InvalidOperationException while checking null value

我正在尝试检查单元格的空值。 我几乎没有收到此错误,因此我需要一些有关如何测试此错误的帮助。 这是我的代码:

private void installBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
    File.WriteAllText("program_names.txt", String.Empty); // Clear program_names file
    int num = 0;
    foreach (DataGridViewRow row in programs_dgv.Rows)
    {
        DataGridViewCheckBoxCell cell = row.Cells[1] as DataGridViewCheckBoxCell;

        if (cell.Value != null)
        {
          ...

我该如何测试和解决这个问题?

请检查单元格!= null && cell.HasValue而不是cell.Value!= null

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM