简体   繁体   English

System.InvalidOperationException,同时检查空值

[英]System.InvalidOperationException while checking null value

I'm trying to check null value of a cell. 我正在尝试检查单元格的空值。 I'm getting this error hardly so I need some help about how to test this. 我几乎没有收到此错误,因此我需要一些有关如何测试此错误的帮助。 Here's my code: 这是我的代码:

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)
        {
          ...

How can I test and fix this? 我该如何测试和解决这个问题?

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

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

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