zaza
zaza

Reputation: 912

WinForms reportViewer (.NET 3.5) binding data from a DataTable

WinForms reportViewer (.NET 3.5) binding data from a DataTable

I'm trying to bind a DataTable which is dynamically created, to a reportViewer control . There are many tutorials on this on the internet but they don't seem to work for this project... (there are related questions on stack overflow but the solutions don't work in my case)

This is the event handler for the Show Report Button:

    private void btn_ShowRwport_Click(object sender, EventArgs e)
    {
        //Set the date range for the report
        rptctn.SetDateRangeOne(listBox1.SelectedItem.ToString(), dateTimePicker_Start.Value, dateTimePicker_End.Value);

        //Get the report datatable
        DataTable dt = rptctn.GetReportTest(listBox1.SelectedItem.ToString());

        //Set the datagridview
        dataGridView1.DataSource = dt;

        //Set the reportViewer
        this.reportViewer1.LocalReport.DataSources.Clear();            
        Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource(dt.TableName, dt);
        this.reportViewer1.LocalReport.DataSources.Add(rprtDTSource);
        this.reportViewer1.RefreshReport();
    }

I know the DataTable is being retried properly as the dataGridView works... https://docs.google.com/file/d/0B6b_N7sDgjmvZHpEYS1BWWhqZ3c/edit?usp=sharing

The project has the following constraints:

Anyone know how i can bind a dynamicly created DataTable to a report viewer in my case?

Upvotes: 0

Views: 2626

Answers (1)

Joey Gennari
Joey Gennari

Reputation: 2361

Really what you're asking to do is dynamically create an RDLC file and add a table. I found a 3rd party example with some code from gotreportviewer.com, just look down on the right hand side of the page for Generate RDLC dynamically - Table.

Upvotes: 1

Related Questions