heres an image 我收到“ System.NullReferenceException,System.Windows.Forms.DataGridViewCell.Value.get返回空值”。当我尝试访问数组中某个单元格的值时出现错误,基本上我想做的是创建2个行数组,然后将datagridview3行传递给它们,如果未选中复选框,则 循环这些数组以将数据发送到数据库。编辑:它显示数组索引为-1
DataGridViewRow[] x = new DataGridViewRow[dataGridView3.Rows.Count];
DataGridViewRow[] y = new DataGridViewRow[dataGridView3.Rows.Count];
if (Convert.ToBoolean(dataGridView3.Rows[row].Cells[onayver.Index].Value) == true)
{
x[row] = dataGridView3.Rows[row];
}
else if (Convert.ToBoolean(dataGridView3.Rows[row].Cells[reddettt.Index].Value) == true)
{
red.Add(dataGridView3.Rows[row]);
}
}
MessageBox.Show(x.Count().ToString());
for (int r = 0; r < x.Count(); r++)
{
infos.randevuisim = x[r].Cells[nameofistek.Index].Value.ToString(); //the error is right here
infos.randevuzaman = x[r].Cells[timeofistek.Index].Value.ToString();
infos.randevukulid = Convert.ToInt32(x[r].Cells[kullaniciofistek.Index].Value.ToString());
Operations.IstekOnayla(infos.randevuisim, infos.randevuzaman, infos.randevukulid);
Operations.KullaniciIstekGoster(dataGridView3);
dataGridView3.AutoResizeColumns();
}