private void dgvAutomoveis_CellContentClick(object sender, DataGridViewCellEventArgs e) { this.dgvAutomoveis.DefaultCellStyle.ForeColor = Color.Black; if (e.ColumnIndex == 5) { AutoDTO dto = dgvAutomoveis.Rows[e.RowIndex].DataBoundItem as AutoDTO; frmAlterarAutomovel tela = new frmAlterarAutomovel(); tela.LoadScreen(dto); tela.Show(); } if (e.ColumnIndex == 6) { AutoDTO dto = dgvAutomoveis.Rows[e.RowIndex].DataBoundItem as AutoDTO; DialogResult resposta = MessageBox.Show("Quer mesmo apagar este registro?", "NerdT", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resposta == DialogResult.Yes) { AutoBusiness business = new AutoBusiness(); business.Remover(dto.Id); MessageBox.Show("Registro removido com sucesso!", "NerdT", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); } } }
void CarregarCboAutomovel() { AutoDTO dto = new AutoDTO(); AutoBusiness buss = new AutoBusiness(); List <AutoDTO> lista = buss.Listar(); cboAuto.ValueMember = nameof(dto.Id); cboAuto.DisplayMember = nameof(dto.Placa); cboAuto.DataSource = lista; }