最近学c#想做个验证器,现在出了点问题

谁能帮帮我,初学,遇到这个问题,看不懂报错

if (string.IsNullOrWhiteSpace(txtUser.Text) || string.IsNullOrWhiteSpace(txtPass.Text))
            {
                MessageBox.Show("请输入用户名和密码!");
                txtUser.Focus();
            }
            else
            {
                bool bFound = false;
                string strFoundUser = txtUser.Text;
                string strFoundPass = txtPass.Text;
                int nRow = dataGridView1.RowCount;
                int targetX = dataGridView1.CurrentCell.RowIndex;
                int targetY = dataGridView1.CurrentCell.ColumnIndex;
                for (int i = 0; i != nRow; i++)
                {
                    if (strFoundUser == dataGridView1.Rows[i].Cells[1].Value.ToString())
                    {
                        dataGridView1.CurrentCell = dataGridView1.Rows[i].Cells[1];
                        targetX = dataGridView1.CurrentCell.RowIndex;
                        targetY = dataGridView1.CurrentCell.ColumnIndex;
                        bFound = true;
                        break;
                    }
                    if (bFound)
                    {
                        break;
                    }

                }
                if (bFound == false)
                {
                    MessageBox.Show("用户名错误!");
                    txtUser.Focus();
                }
                else
                {
                    if (strFoundPass == dataGridView1.Rows[targetX].Cells[targetY+1].Value.ToString())
                    {
                        new frmMain();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("密码错误!");
                        txtUser.Focus();
                    }
                }
            }
        }

报错截图放在这里

img

dataGridView1.Rows[i].Cells[1].Value
这个是Null

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^