I have a datagridview with a checkbox column, and I want to delete the row that is checked by a delete button. However, some other rows which is unchecked was deleted instead of the checked row. I got an list object(srv_NameList) to store the value of each row which are used to delete the record, any value that store in that list will be delete once the button is clicked :
private void dataGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e) {
if (dataGrid.Columns[e.ColumnIndex].Name.Equals("Select"))
{
if (dataGrid.Rows[e.RowIndex].Selected == true)
{
string srvName = dataGrid.Rows[e.RowIndex].Cells["ServiceName"].Value.ToString();
srv_NameList.Add(srvName);
}
if (dataGrid.Rows[e.RowIndex].Selected == false)
{
string srvName_del = dataGrid.Rows[e.RowIndex].Cells["ServiceName"].Value.ToString();
if (srv_NameList.Contains(srvName_del))
{
srv_NameList.Remove(srvName_del);
}
}
}
}
Can someone kindly tell me what's wrong here?
Aucun commentaire:
Enregistrer un commentaire