C#打印控件ReportViewer使用总结(三)
创始人
2024-11-10 18:35:44

ReportViewer控件设计

  1. 在工具箱中添加ReportViewer控件,控件名称为reportViewer1。

2.绑定报表和数据集

        /// 

        /// 绑定报表和数据集

        /// 

        private void DataBing()

        {

            //绑定报表

            this.reportViewer1.LocalReport.ReportPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\Report1.rdlc";

            Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource();

            this.components = new System.ComponentModel.Container();

            this.bsPrintInfo = new System.Windows.Forms.BindingSource(this.components);

            ((System.ComponentModel.ISupportInitialize)(this.bsPrintInfo)).BeginInit();

            rds.Name = "PrintInfo";

            rds.Value = this.bsPrintInfo;

            this.reportViewer1.LocalReport.DataSources.Add(rds);

            this.bsPrintInfo.DataSource = typeof(WinformReportTest.PrintInfo);

            ((System.ComponentModel.ISupportInitialize)(this.bsPrintInfo)).EndInit();

        }

3.将打印数据导入到预览窗体并显示。

        /// 

        /// 预览

        /// 

        /// 

        /// 

        private void btnPrintShow_Click(object sender, EventArgs e)

        {

            PrintInfo info = new PrintInfo();

            info.Name = txtName.Text.Trim();

            info.Sex = txtSex.Text.Trim();

            info.Age = txtAge.Text.Trim();

            info.Description = txtDesc.Text.Trim();

            FormReport report = new FormReport(info);

            report.ShowDialog();

        }

  1. 显示效果。

使用实例:https://download.csdn.net/download/sunsddd/87922367

相关内容

热门资讯

裸辞做“一人公司”,我后悔了 去年这个时候,一位以色列程序员正在东南亚旅行。他顺手把一个在脑子里转了很久的想法做成了产品,一个让任...
南京建成国内首个Pre-6G试... 4月21日,2026全球6G技术与产业生态大会在南京开幕。全息互动技术展台前,一名远在北京的工作人员...
超梵求职受邀参加“2025抖音... 超梵求职受邀参加“2025抖音巨量引擎成人教育行业生态大会”,探讨分享优质内容传播,服务万千学员。 ...
摩托罗拉Razr 2026(R... IT之家 4 月 22 日消息,摩托罗拉宣布新一代 Razr 折叠手机将于 4 月 29 日在美国发...
库克卸任,特纳斯领航:苹果新纪... 苹果首席执行官蒂姆·库克将卸任,硬件工程主管约翰·特纳斯将接任,苹果公司今天宣布此事。 库克将在夏季...