找回密码
 立即注册

QQ登录

只需一步,快速开始

cyh9519

论坛元老

7

主题

17

帖子

5019

积分

论坛元老

积分
5019

活字格认证

cyh9519
论坛元老   /  发表于:2014-5-4 18:27  /   查看:6175  /  回复:3
版主好,我要在Winform项目中给PageReport动态绑定数据源,我在博客中找到了ASP.net中动态绑定的案例,调试也成功了,参照着写了一个winform的,运行后报表显示错误。请帮我看一下是什么问题,代码和错误如附件,代码很简单:

        private void Form3_Load(object sender, EventArgs e)
        {
            DisplayReportThread();
        }

        private void DisplayReportThread()
        {

            try
            {
                GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();
                report.Load(new System.IO.FileInfo(@"..\..\PageReport1.rdlx"));
                report.Document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(Document_LocateDataSource);
                report.Run();
                GrapeCity.ActiveReports.Document.PageDocument document1 = new GrapeCity.ActiveReports.Document.PageDocument(report);
                viewer1.LoadDocument(document1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }

        }

        void Document_LocateDataSource(object sender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args)
        {
            if (args.DataSourceName == "DataSource1" && args.DataSetName == "DataSet1")
            {
                args.Data = GetData();
            }

        }

        private DataTable GetData()
        {

            DataTable dt = new DataTable("");
            dt.Columns.Add("Col1");
            dt.Columns.Add("Col2");
            dt.Columns.Add("Col3");
            dt.Rows.Add(1, 1, 1);
            dt.Rows.Add(2, 1, 1);
            dt.Rows.Add(3, 1, 1);
            dt.Rows.Add(4, 1, 1);
            dt.Rows.Add(5, 1, 1);
            dt.Rows.Add(6, 1, 1);

            return dt;
        }


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

3 个回复

倒序浏览
roger.wang
社区贡献组   /  发表于:2014-5-5 10:32:00
沙发
回复 1楼cyh9519的帖子

代码写的不错,赞一个。

修改如下试试:


  1. GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport();
  2.                 //report.Document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(Document_LocateDataSource);
  3.                 report.Load(new System.IO.FileInfo(@"..\..\PageReport1.rdlx"));
  4.                 report.Run();
  5.                 GrapeCity.ActiveReports.Document.PageDocument document1 = new GrapeCity.ActiveReports.Document.PageDocument(report);
  6.                 document1.LocateDataSource += Document_LocateDataSource;
  7.                 viewer1.LoadDocument(document1);
复制代码


需要用new过后的PageDocument加载数据源: document1.LocateDataSource
回复 使用道具 举报
cyh9519
论坛元老   /  发表于:2014-5-5 17:43:00
板凳
回复 2楼roger.wang的帖子

感谢版主,根据提示已经解决问题
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-5-6 13:59:00
地板
回复 3楼cyh9519的帖子

感谢反馈问题结果。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部