private void btnSalvar_Click(object sender, EventArgs e) { if (dtvInfAlunos != null) { DataGridViewSelectedCellCollection selectedCells = dtvInfAlunos.SelectedCells; string matricula = selectedCells[0].FormattedValue.ToString(); string nome = selectedCells[1].FormattedValue.ToString(); string dataNascimento = selectedCells[2].FormattedValue.ToString(); string curso = selectedCells[3].FormattedValue.ToString(); CursoRepositorio cursoRepositorio = new CursoRepositorio(); Curso objCurso = cursoRepositorio.obtemPorNome(curso); if (objCurso == null) { return; } Aluno aluno = new Aluno(Convert.ToInt32(matricula), Convert.ToDateTime(dataNascimento), nome, objCurso); AlunoRepositorio alunoRepositorio = new AlunoRepositorio(); if (alunoRepositorio.editaAluno(aluno) == 1) { MessageBox.Show("Os dados do aluno foram alterados com sucesso!"); btnBuscarAluno_Click(sender, e); } } }