private void btnGerarRelatorio_Click(object sender, EventArgs e) { List <ClassAluno> lst = new List <ClassAluno>(); lst.Clear(); for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { ClassAluno aluno = new ClassAluno { Nome = dataGridView1.Rows[i].Cells[0].Value.ToString(), Idade = int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()), Sexo = dataGridView1.Rows[i].Cells[2].Value.ToString(), Telefone = dataGridView1.Rows[i].Cells[3].Value.ToString(), }; lst.Add(aluno); } rs.Name = "DataSet1"; rs.Value = lst; FormRelatorioAluno relatorio = new FormRelatorioAluno(); relatorio.reportViewer1.LocalReport.DataSources.Clear(); relatorio.reportViewer1.LocalReport.DataSources.Add(rs); relatorio.reportViewer1.LocalReport.ReportEmbeddedResource = "Projeto 03- Senai.Report1.rdlc"; relatorio.ShowDialog(); }
private void btnGerarRelatorio_Click(object sender, EventArgs e) { // gera a lista que será o valor inserido no datasource List <ClassAluno> lst = new List <ClassAluno>(); lst.Clear(); // inserção dos dados na lista for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { DateTime dataNascimentoTotal = Convert.ToDateTime(dataGridView1.Rows[i].Cells[2].Value.ToString()); string dataNascimentoParcial = dataNascimentoTotal.ToString("dd/MM/yyyy"); DateTime dataMatriculaTotal = Convert.ToDateTime(dataGridView1.Rows[i].Cells[74].Value.ToString()); string dataMatriculaParcial = dataMatriculaTotal.ToString("dd/MM/yyyy"); ClassAluno aluno = new ClassAluno { RaAluno = dataGridView1.Rows[i].Cells[0].Value.ToString(), AlunoNome = dataGridView1.Rows[i].Cells[1].Value.ToString(), Nascimento = dataNascimentoParcial, IdadeAluno = int.Parse(dataGridView1.Rows[i].Cells[3].Value.ToString()), Sexo = dataGridView1.Rows[i].Cells[4].Value.ToString(), GrauInstrucao = dataGridView1.Rows[i].Cells[5].Value.ToString(), Rua = dataGridView1.Rows[i].Cells[6].Value.ToString(), Numero = dataGridView1.Rows[i].Cells[7].Value.ToString(), Complemento = dataGridView1.Rows[i].Cells[8].Value.ToString(), Bairro = dataGridView1.Rows[i].Cells[9].Value.ToString(), Estado = dataGridView1.Rows[i].Cells[10].Value.ToString(), Cidade = dataGridView1.Rows[i].Cells[11].Value.ToString(), Cep = dataGridView1.Rows[i].Cells[12].Value.ToString(), Telefone1 = dataGridView1.Rows[i].Cells[13].Value.ToString(), Identidade = dataGridView1.Rows[i].Cells[14].Value.ToString(), Cpf = dataGridView1.Rows[i].Cells[15].Value.ToString(), Email = dataGridView1.Rows[i].Cells[16].Value.ToString(), CarteiraTrabalho = dataGridView1.Rows[i].Cells[17].Value.ToString(), NomePai = dataGridView1.Rows[i].Cells[31].Value.ToString(), TelefonePai = dataGridView1.Rows[i].Cells[32].Value.ToString(), NomeMae = dataGridView1.Rows[i].Cells[37].Value.ToString(), TelefoneMae = dataGridView1.Rows[i].Cells[38].Value.ToString(), NomeCurso = dataGridView1.Rows[i].Cells[58].Value.ToString(), CodTurma = dataGridView1.Rows[i].Cells[60].Value.ToString(), StatusAluno = dataGridView1.Rows[i].Cells[62].Value.ToString(), DataMatricula = dataMatriculaParcial, Telefone2 = dataGridView1.Rows[i].Cells[84].Value.ToString(), }; lst.Add(aluno); } // insere um nome no datasource rs.Name = "DataSet1"; // insere a lista como valor no datasource rs.Value = lst; FormRelatorioAluno relatorio = new FormRelatorioAluno(); // limpa os registros anteriores do reportviewer relatorio.reportViewer1.LocalReport.DataSources.Clear(); // impõe o datasource criado como datasource do reportviewer do FormRelatorioAluno relatorio.reportViewer1.LocalReport.DataSources.Add(rs); relatorio.ShowDialog(); }