foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[1].Value != null && (bool)row.Cells[1].FormattedValue)
{
DialogResult dlgRes;
string teststr = "Are you want to delete";
dlgRes = MessageBox.Show(teststr, "Confirm Document Close", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dlgRes == DialogResult.Yes)
{
int idtoselect = (int)row.Cells[0].Value;
String str1 = idtoselect.ToString();
string constr = "DELETE FROM Member Where ID_Member =" + str1 + "";
SqlCommand cmd = new SqlCommand(constr, conn);
cmd.ExecuteNonQuery();
ds.Tables["Member"].Clear();
da.Fill(ds, "Member");
dataGridView1.DataSource = ds.Tables["Member"];
}
else
{
ds.Tables["Member"].Clear();
da.Fill(ds, "Member");
dataGridView1.DataSource = ds.Tables["Member"];
}
}
}
this's my code to delete record that choose by checkbox and checkbox in datagridview Row cell 1
and id is datagridview Row cell 0
Hope you bring my code to apply for your question