//Cuando hagan doble click en el contenido de la celda se activa este evento private void gridContacts_CellContentClick(object sender, DataGridViewCellEventArgs e) { //Con esta Linea obtengo la celda que han cliqueado //Se debe castear para que el dato que devuelva sea del mismo tipo de la variable "cell". DataGridViewLinkCell cell = (DataGridViewLinkCell)gridContacts.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (cell.Value.ToString() == "Edit") { ContactDetails contactDetails = new ContactDetails(); contactDetails.LoadContact(new Contact { Id = int.Parse(gridContacts.Rows[e.RowIndex].Cells[0].Value.ToString()), FirstName = gridContacts.Rows[e.RowIndex].Cells[1].Value.ToString(), LastName = gridContacts.Rows[e.RowIndex].Cells[2].Value.ToString(), Phone = gridContacts.Rows[e.RowIndex].Cells[3].Value.ToString(), Address = gridContacts.Rows[e.RowIndex].Cells[4].Value.ToString(), }); contactDetails.ShowDialog(this); } else if (cell.Value.ToString() == "Delete") { DeteleContact(int.Parse(gridContacts.Rows[e.RowIndex].Cells[0].Value.ToString())); PopulateContacts(); } }
private void gridContacts_CellContentClick(object sender, DataGridViewCellEventArgs e) { DataGridViewLinkCell cell = (DataGridViewLinkCell)gridContacts.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (cell.Value.ToString() == "Edit") { ContactDetails contactDetails = new ContactDetails(); contactDetails.LoadContact(new Contact { Id = int.Parse((gridContacts.Rows[e.RowIndex].Cells[0]).Value.ToString()), FirstName = gridContacts.Rows[e.RowIndex].Cells[1].Value.ToString(), LastName = gridContacts.Rows[e.RowIndex].Cells[2].Value.ToString(), Phone = gridContacts.Rows[e.RowIndex].Cells[3].Value.ToString(), Address = gridContacts.Rows[e.RowIndex].Cells[4].Value.ToString(), }); contactDetails.ShowDialog(this); } else if (cell.Value.ToString() == "Delete") { DeleteContact(int.Parse((gridContacts.Rows[e.RowIndex].Cells[0]).Value.ToString())); PopulateContacts(); } }