I am developing an app in C# in which I am using the datagridview and gridview first column contains the checkboxes and I want to chech the checkbox is true or not but it is giving me the exception of ‘Object referernce is not set to an instance of an object’. The code is following
private void btnDelete_Click(object sender, EventArgs e)
{
StudentDAL s = new StudentDAL();
try
{
for (int i = 0; i < this.dataGridView1.RowCount; i++)
{
if (!DBNull.Value.Equals(this.dataGridView1.Rows[i].Cells[0]) && (bool)this.dataGridView1.Rows[i].Cells[0].Value == true)
{
s.delete(Convert.ToInt32(this.dataGridView1.Rows[i].Cells[1].Value));
i--;
}
}
this.dataGridView1.DataSource = s.getAll();
}
catch (Exception nn)
{
}
}
Please help me.
First you have to find your CheckBox control, then you can check it is checked or not like this :