none
RDLC Report PrintDialog() 出错。 RRS feed

  • 问题

  • 大家好,我做了一个RDLC report。 在打印的时候不想先预览报表,想点一个button后,直接跳出打印的dialog。 我的代码如下。系统提示“对象的当前状态使该操作无效”。请大家帮忙。
    谢谢大家

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using Microsoft.Reporting.WinForms;
    using System.Windows.Forms;
    using System.IO;
    using WHHRdlc;
    using System.Drawing.Printing;
    using System.ComponentModel;
    using System.Data;

    namespace WpfApplicationTest1
    {
        /// <summary>
        /// Interaction logic for Window1.xaml
        /// </summary>
       
        public partial class Window1 : Window
        {
            Microsoft.Reporting.WinForms.ReportViewer rep;
            public Window1()
            {
                InitializeComponent();
                string strMimeType;
                string strEncoding;
                string strFileNameExtension;
         
                String[] strStreamIds = new String[1];
                Microsoft.Reporting.WinForms.Warning[] Warnings = new Microsoft.Reporting.WinForms.Warning[1];

                rep = windowsFormsHost1.Child as Microsoft.Reporting.WinForms.ReportViewer;
                rep.LocalReport.ReportPath = "Report1.rdlc";
                rep.ShowExportButton = true;

                DataTable dt = GetData();
                ReportDataSource rds = new ReportDataSource("DataSet_DataTable1", dt);
                rep.LocalReport.DataSources.Clear();
                rep.LocalReport.DataSources.Add(rds);
                rep.LocalReport.Refresh();        
            }



             private DataTable GetData()
             {
                DataTable dt = new DataTable("DataSet_DataTable1");
                dt.Columns.Add(new DataColumn("name", typeof(string)));
                dt.Columns.Add(new DataColumn("income", typeof(decimal)));
                dt.Columns.Add(new DataColumn("dept", typeof(string)));

                DataRow row = dt.NewRow();
                row["name"] = "aaaa";

                             row["income"] = 1000.00;
                row["dept"] = "bbbb";
                dt.Rows.Add(row);


                return dt;
                }

             private void button1_Click(object sender, RoutedEventArgs e)
             {
               
                 rep.PrintDialog();
             }
        }
    }
    2009年12月2日 2:32

答案

全部回复