Getting the error :
System.NullReferenceException
for the below code on a C# Windows form.
try
{
foreach (DataGridViewRow row in dataGridView2.Rows)
{
if (row.Cells["txtAttendance_Status"].Value.ToString() == "Attended")
{
row.Cells["txtStatus"].Value = true;
}
else if (row.Cells["txtAttendance_Status"].Value.ToString() == "Not Attended")
{
row.Cells["txtStatus"].Value = false;
}
else
{
row.Cells["txtStatus"].Value = false;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error", ex.ToString());
}
Below is the table :