1

伙计们

我尝试使用实体数据模型在 WPF 窗口中加载水晶报表,但它没有加载,如何加载它?

我使用了这个教程,但我的环境是 VS2012

http://www.c-sharpcorner.com/UploadFile/nipuntomar/crystal-report-viewer-in-wpf-part-1/

这是我的代码:

 using CrystalDecisions.CrystalReports.Engine;
 using CrystalDecisions.Shared;
 private void crystalReportsViewer1_Loaded(object sender, RoutedEventArgs e)
    {
        ReportDocument report = new ReportDocument();
        report.Load("CrystalReport1.rpt");
        using (cvmakerEntities1 db = new cvmakerEntities1())
        {
            report.SetDataSource(from c in db.cvs
             select new {c.Full_Name,c.Address,c.E_Mail,c.Activities,c.Birth_Day,c.Courses,c.Education,c.Experience,c.Gender,c.Mobile,c.Nationality,c.Occuptional_Field,c.Personnal_Website,c.photo,c.Skills,c.Tele});
        }
        crystalReportsViewer1.ViewerCore.ReportSource = report;
    } 

这是 xml 设计器中的代码

<Window x:Class="CV_Maker.Report"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:my="clnamespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
    Title="Report" Height="800" Width="800">
<Grid>
    <my:CrystalReportsViewer HorizontalAlignment="Left" Name="crystalReportsViewer1"
                             VerticalAlignment="Top" Height="769" Width="792" Loaded="crystalReportsViewer1_Loaded" />
</Grid>

这里有什么问题 ?

谢谢

4

1 回答 1

0

我相信问题是您正在 CrystalReportViewer_Loaded 中加载报告

如文章所述,将您的报表加载设置在 Window_Loaded 事件中,并删除 CrystalReportViewer 的 xaml 代码中的 Loaded 事件:

1)删除加载属性:

<my:CrystalReportsViewer HorizontalAlignment="Left" Name="crystalReportsViewer1"
                         VerticalAlignment="Top" Height="769" Width="792" Loaded="crystalReportsViewer1_Loaded" />

2)添加窗口加载事件:

<Window xmlns:Viewer="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer" ... Loaded="Window_Loaded">

2) 在 xaml.cs 中重命名事件

private void crystalReportsViewer1_Loaded(object sender, RoutedEventArgs e)

private void Window_Loaded(object sender, RoutedEventArgs e) { 
...
}
于 2014-12-20T17:35:00.853 回答