C#打印控件ReportViewer使用总结(三)

ReportViewer控件设计

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

C#打印控件ReportViewer使用总结(三)_第1张图片 

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.将打印数据导入到预览窗体并显示。

        /// 

        /// 预览

        /// 

        ///  name="sender">

        ///  name="e">

        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. 显示效果。

C#打印控件ReportViewer使用总结(三)_第2张图片C#打印控件ReportViewer使用总结(三)_第3张图片

 

 

你可能感兴趣的:(c#,c#,开发语言)