private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { index = e.RowIndex; if (e.RowIndex >= 0) { // Lay ID cua ban ghi duoc chon --> chuan bi cho Xem, Sua, Xoa int id = Convert.ToInt32(dataGridView1.SelectedCells[0].OwningRow.Cells[0].Value.ToString()); // Xu ly cac truong hop Xem(detail), Sua(edit), Xoa(delete) if (e.ColumnIndex == dataGridView1.Columns["detail"].Index) { // Code xu ly lay du lieu tu ban ghi chuyen sang FormDetailSupplier maNCC = dataGridView1.Rows[index].Cells[0].Value.ToString(); tenNCC = dataGridView1.Rows[index].Cells[1].Value.ToString(); diaChi = dataGridView1.Rows[index].Cells[2].Value.ToString(); sdt = dataGridView1.Rows[index].Cells[3].Value.ToString(); email = dataGridView1.Rows[index].Cells[4].Value.ToString(); // Hien thi FormDetailSupplier FormDetailSupplier form = new NhaCungCap.FormDetailSupplier(); form.ShowDialog(); dataGridView1.DataSource = ctr.Load(); } else if (e.ColumnIndex == dataGridView1.Columns["edit"].Index) { // Code xu ly lay du lieu tu ban ghi chuyen sang FormEditSupplier maNCC = dataGridView1.Rows[index].Cells[0].Value.ToString(); tenNCC = dataGridView1.Rows[index].Cells[1].Value.ToString(); diaChi = dataGridView1.Rows[index].Cells[2].Value.ToString(); sdt = dataGridView1.Rows[index].Cells[3].Value.ToString(); email = dataGridView1.Rows[index].Cells[4].Value.ToString(); // Hien thi FormEditSupplier Form form = new NhaCungCap.FormEditSupplier(); form.ShowDialog(); dataGridView1.DataSource = ctr.Load(); } else if (e.ColumnIndex == dataGridView1.Columns["delete"].Index) { DialogResult dlr = MessageBox.Show("Chắc chắn xoá ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlr == DialogResult.Yes) { // Code xu ly xoa nha cung cap maNCC = dataGridView1.Rows[index].Cells[0].Value.ToString(); ctr.Delete(maNCC); dataGridView1.DataSource = ctr.Load(); } } } }