NullReferenceException:System.Windows.Forms.DataGridView.CurrentRow.get返回null

时间:2018-05-10 13:46:09

标签: c# winforms

我有这段代码:

private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Rows.Count > 0)
            {
                txtMaNCC.Text = dataGridView1.CurrentRow.Cells["MaNCC"].Value.ToString();
                txtTenNCC.Text = dataGridView1.CurrentRow.Cells["TenNCC"].Value.ToString();
                txtDiaChi.Text = dataGridView1.CurrentRow.Cells["DiaChi"].Value.ToString();
                txtDienThoai.Text = dataGridView1.CurrentRow.Cells["DienThoai"].Value.ToString();
                txtNguoiDaiDien.Text = dataGridView1.CurrentRow.Cells["NguoiDaiDien"].Value.ToString();
            }
        }

当我点击datagridview1中的一行时,它停了下来并给了我一条消息:

  

NullReferenceException:System.Windows.Forms.DataGridView.CurrentRow.get返回null。

0 个答案:

没有答案