本文介绍了使用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.

推荐答案


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

10-22 16:03