1
我正在使用Visual Studio 2005与VB.NET。帮助从CrystalReportViewer解耦水晶报表
我有许多Crystal Reports,每个都有自己关联的包含CrystalReportViewer的关联对话框资源。类定义是这样的:
Imports System.Windows.Forms
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class dlgForMyReport
Private theReport As New myCrystalReport
Public theItems As New List(Of MyItem)
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub dlgForMyReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
theReport.SetDataSource(theItems)
'Do a bunch of stuff here to set data items in theReport
Me.myCrystalReportViewer.ReportSource = theReport
End Sub
End Class
我基本上实例的对话框中,设置theItems到列表我想要的,并调用ShowDialog的。
我现在需要将其中几个报告合并到一个报告中(possibly like this),但加载报告中字段的代码位于对话框中。
我该如何解决报表初始化与对话框的脱钩问题?
谢谢!
感谢罗兰。如果我理解正确,那么我只需在别处加载报告数据,设置并绑定CrystalReport对象,并显示对话框? – John 2010-03-16 15:01:34
@John就是这样。实际上,您需要更改代码,以便'theReport'作为CrystalReport类型的属性公开,然后可以将其设置为新的'myCrystalReport'并显示该对话框或任何其他CrystalReport对象 – 2010-03-16 15:39:40
像魅力一样工作。谢谢! – John 2010-03-18 00:27:39