Doubt on how to print datagridview in reportviewer

4

I need to print data from a DataGridViewer, which gets the products launched for sale. What is the best way to print this information in Report? I tried to use the Table component, but I can not pass the information to it, since it needs to be bound to a DataSet.

Here is the form constructor where the report is located:

    public frmTesteImpressaoVenda(String nomeEmpresa, String enderecoEmpresa, String cnpjEmpresa, String telefoneEmpresa,
        String nomeCliente, String cpjCliente, DateTime DataVenda, String Pagamento) {

        InitializeComponent();
        reportVenda.LocalReport.ReportEmbeddedResource = "GUI.ImpressaoVenda.rdlc";

        ReportParameter[] parms = new ReportParameter[8];
        parms[0] = new ReportParameter("NomeEmpresa", nomeEmpresa);
        parms[1] = new ReportParameter("EnderecoEmpresa", enderecoEmpresa);
        parms[2] = new ReportParameter("CnpjEmpresa", cnpjEmpresa);
        parms[3] = new ReportParameter("Telefone", telefoneEmpresa);
        parms[4] = new ReportParameter("Cliente", nomeCliente);
        parms[5] = new ReportParameter("Cpf", cpjCliente);
        parms[6] = new ReportParameter("DataVenda", DataVenda.ToString());
        parms[7] = new ReportParameter("Pagamento", Pagamento);

        reportVenda.LocalReport.SetParameters(parms);
        reportVenda.LocalReport.Refresh();
        reportVenda.RefreshReport();

    }

The code below is the sales form where you pass the parameters to fill the report.

    private void btImprimirTeste_Click(object sender, EventArgs e) {
        frmTesteImpressaoVenda impVenda = new frmTesteImpressaoVenda(
            CadastroEmpresa.nome_empresa,
            CadastroEmpresa.endereco + ", " + CadastroEmpresa.numendereco + " - " + CadastroEmpresa.bairro + " - " + CadastroEmpresa.cidade,
            CadastroEmpresa.cnpj,
            CadastroEmpresa.telefone,
            txtNomeCliente.Text,
            lbCpf.Text,
            DateTime.Now,
            cbTipoPagto.Text
        );

        impVenda.Show();

    }
    
asked by anonymous 24.10.2016 / 18:01

1 answer

0

Hello.

To use Table in Report is relatively simple. You can create a Typed DataSet and add it to your Report.

  • Display "Report Data" panel - View - > Report Data
  • Right-click "DataSets" and "Add Dataset ..."

In this way you can link an Object to be the model of your data set or even the DataSet Tipado if this is your choice.

Through the wizard you can easily add a DataSource to your Report.

When you insert the Table into your report (through the Toolbox), you can add the columns and bind them to a property of your DataSource.

It is important to remember that the Table has a "DataSetName" property, which defines the name of the dataset that will be displayed in the table. This property is important so you can "set" the dataset in your ReportDataSource through the code:

 ReportDataSource rds = new ReportDataSource("DataSet1");
 rds.Value = repositorio.GetData();
 ReportViewer1.LocalReport.DataSources.Add(rds);

Here's an example with the typed DataSet: Example

    
09.11.2016 / 13:44