使用Crystal报表视图仅在一个表单中打开更改报表 [英] Change Report open in only one form with Crystal Report View

查看:135
本文介绍了使用Crystal报表视图仅在一个表单中打开更改报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

我有树状视图和打印按钮的报告列表。当我选择rpt1然后单击打印按钮时,将使用rptviewer1在frm1中打开rpt1。然后我在树视图中选择另一个rpt2并使用rptviewer1在frm2中打开rpt2。但是,每当我在树状视图中选择报告并单击打印按钮时,我只想使用一个表单来打开报告。我该怎么做才能打开报告。我想只使用一个带有reportviewer1的表单。

谢谢。



这是我的代码。

//报表打印表单,带有报表列表和打印按钮的树视图。当打印btn点击代码//如下

Print_Click()

{

switch(this.Report_Tree.SelectedNode.Name)

{

案例Rpt1:

//有一个带有报告的form1 crystalrptviewer1

frmRpt1 frm1 = new frmRpt1();

frm1.ShowDialog();

break;

case Rpt2:

//有一个form2 with报告crystalrptviewer1

frmRpt2 frm2 = new frmRpt2();

frm2.ShowDialog();

break;

默认值:

休息;

}



}



//在frmRpt1代码中如下

公共部分类frmRpt1:表格

{

BindingSource bsRpt;

DataTable dtRpt;



public frmRpt1()

{

InitializeComponent();



bsRpt; = new BindingSource();

dtRpt; = new DataTable();



Rpt1 rpt = new Rpt1();



dtRpt = GetDataTable( 选择*来自table1);

bsRpt.DataSource = dtRpt;

rpt.SetDataSource(dtRpt);

crystalReportViewer1.ReportSource = rpt ;

}

}

//在frmRpt2代码中如下所示

公共部分类frmRpt2:表格

{

BindingSource bsRpt;

DataTable dtRpt;



public frmRpt2()

{

InitializeComponent();



bsRpt; = new BindingSource();

dtRpt; = new DataTable();



Rpt2 rpt = new Rpt2();



dtRpt = GetDataTable( 选择*来自table1);

bsRpt.DataSource = dtRpt;

rpt.SetDataSource(dtRpt);

crystalReportViewer1.ReportSource = rpt ;

}

}



所以我只想使用一个frmRpt表格。然后当点击打印时,将frmrpt的crystalreportviewer1的报告源更改为任何Rpt1,Rpt2或任何其他。它可以与否?请帮我。谢谢。

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.

推荐答案

不需要多个表单来显示多个报表。您只需根据条件动态调用相应的报告(rpt AND / OR数据源)即可。检查这个



如何运行动态在VS.NET中使用Crystal Report Viewer的Crystal Report [ ^ ]
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[^]


这篇关于使用Crystal报表视图仅在一个表单中打开更改报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆