Doubt on how to print datagridview in reportviewer

Asked

Viewed 977 times

5

I need to print the data of a Datagridviewer, which is the products launched in the sale. What is the best way to print this information in the Report? I tried to use the Table component, but I can’t pass the information to him, since he needs to be linked to a Dataset.

One observation is that I have some textbox in the report.rldc that I was able to fill using parameters, but now to print the information of a Datagrid I ended up grabbing.


Here is the constructuor of the form where the report is:

    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 in 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();

    }
  • what you have done, could put?

1 answer

1

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 on "Datasets" and "Add Dataset..."

This way you can link an Object to be the model of your data set or even the Typed Dataset if this is your option.

Through Wizard you can easily add a Datasource to your Report.

By inserting the Table in your report (through Toolbox), you can add the columns and bind them to a property of your Datasource.

It is important to remember that Table has a "Datasetname" property, which defines the name of the dataset that will be displayed in the table. This property is important for you to "set" the dataset in your Reportdatasource via code:

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

Here’s an example with typed Dataset: Example

Browser other questions tagged

You are not signed in. Login or sign up in order to post.