Click here to Skip to main content
16,006,605 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
I have Report list of tree view and print button. When I select rpt1 and then click print button, rpt1 is opened in frm1 with rptviewer1. And then I select another rpt2 in tree view and open rpt2 in frm2 with rptviewer1. But I want to use only one form to open report whenever I select report in tree view and click print button. How can I do it to open report. I want to use only one form with reportviewer1.
Thanks you.

Here is my code.
//in report print form with treeview of report list and print button. When print btn click code //as below
Print_Click()
{
switch (this.Report_Tree.SelectedNode.Name)
{
case Rpt1:
//there is a form1 with report crystalrptviewer1
frmRpt1 frm1 = new frmRpt1();
frm1.ShowDialog();
break;
case Rpt2:
//there is a form2 with report crystalrptviewer1
frmRpt2 frm2 = new frmRpt2();
frm2.ShowDialog();
break;
default:
break;
}

}

//in frmRpt1 code as below
public partial class frmRpt1 : Form
{
BindingSource bsRpt;
DataTable dtRpt;

public frmRpt1()
{
InitializeComponent();

bsRpt; = new BindingSource();
dtRpt; = new DataTable();

Rpt1 rpt = new Rpt1();

dtRpt = GetDataTable("Select * From table1");
bsRpt.DataSource = dtRpt;
rpt.SetDataSource(dtRpt);
crystalReportViewer1.ReportSource = rpt;
}
}
//in frmRpt2 code as below
public partial class frmRpt2 : Form
{
BindingSource bsRpt;
DataTable dtRpt;

public frmRpt2()
{
InitializeComponent();

bsRpt; = new BindingSource();
dtRpt; = new DataTable();

Rpt2 rpt = new Rpt2();

dtRpt = GetDataTable("Select * From table1");
bsRpt.DataSource = dtRpt;
rpt.SetDataSource(dtRpt);
crystalReportViewer1.ReportSource = rpt;
}
}

So I want to use only one frmRpt form. And then when click print chang the reportsource of crystalreportviewer1 of frmrpt for any Rpt1, Rpt2 or anyother. It can be or not? Please help me. Thanks you.
Posted
Updated 11-Nov-13 17:45pm
v2
Comments
thatraja 6-Nov-13 5:37am    
Show code
Member 10297003 11-Nov-13 23:26pm    
Hi! thatraja
Sorry I have a trip so I can't know your reply for show code. Now I will show my code.

1 solution

There's no need for multiple forms to display multiple reports. You just need to call the appropriate report(rpt AND/OR datasource) dynamically based on condition, that's it. Check this

How to run Dynamic Crystal Report using Crystal Report Viewer in VS.NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900