开发者

Showing Crystal Report on a WPF Application(Visual Studio 2008)

In Windows Form app开发者_运维问答lication, it was as trivial as Creating a Form and bind the RPT file to the Form. Looks like this option isn't possible with WPF.

I would like to show a Crystal Report on a new Window when a button is clicked. How to achieve this with WPF.


What version of Visual Studio are you using? If VS2010, there is a WPF CrystalReportViewer available for download.


It can be done by using the Window Class:

See code below for demonstration

MyWindowType myReport = new MyWindowType(); // create a window, MyWindow is an User Control of type Window, that is it extends Window

MyCrystalReport myReport = new MyCrystalReport();
// Do necessary modifications to myReport such as Add Data and Send Parameters
CrystalReportViewer rptViewer = new CrystalReportViewer(); // Construct a ReportViewer
WindowsFormsHost host = new WindowsFormsHost(); // Create a WindowsFormsHost
rptViewer.ReportSource = myReport; // Add Report to ReportSource 
host.Child = rptViewer; // Add report viewer as child to host
myReport.reportGrid.Children.Add(host); // Add host to MainWindow, that is myReport in this example
myReport.BringIntoView();
myReport.Show();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜