private void buttonXoa_Click(object sender, EventArgs e) { DialogResult res = MessageBox.Show("Xóa tham số", "Tham số", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); //Lấy vị trí cần xóa if (res == DialogResult.Yes) { Index = dataGridViewThamSo.CurrentRow.Index; string id = dataGridViewThamSo.CurrentRow.Cells["ColMaThamSo"].Value.ToString().Trim(); int stt = int.Parse(dataGridViewThamSo.CurrentRow.Cells["ColSTT"].Value.ToString()); if (ThamSoBUS.DeleteThamSoById(id)) { dataGridViewThamSo.Rows.RemoveAt(Index); if (dataGridViewThamSo.Rows.Count > 0) { bool flag = false; for (int i = 0; i < Index; i++) { if (dataGridViewThamSo.Rows[i].Visible == true) { flag = true; } } for (int i = Index; i < dataGridViewThamSo.Rows.Count; i++) { if (dataGridViewThamSo.Rows[i].Visible == true) { dataGridViewThamSo.Rows[i].Cells["ColSTT"].Value = stt.ToString(); stt++; flag = true; } } if (flag == false) { buttonDisabled(); } } else { buttonDisabled(); } } } }