使用本地报表报表查看器类打印Winforms [英] Print Winforms using local report report viewer classes

查看:58
本文介绍了使用本地报表报表查看器类打印Winforms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以在下面的查询中提供帮助吗?



1.使用本地报告/报告查看器的打印功能仅限单页。

有没有办法打印所有页面?



当我只打印一页时会打印但在打印页面上显示1/6(报告总页数) )。$


我试过将deviceInfo的startPage属性设置为Zero,但它对我没有用。



2.在打印预览中,它显示的页面较少,但在打印时会打印更多页面。

E,g。如果它在打印预览上显示总共3页,则在打印时实际打印6页。

解决方案

嗨Rajesh111,


>> 1.使用本地报告/报告查看器的打印功能仅限单页。有没有办法打印所有页面?


我不知道你是怎么写代码的,我做了一个简单的演示,请参考它如下所示:


第1步:创建课程:

 class Customers 
{
public string CustomerId {get;组; }
公共字符串ContactName {get;组; }
public string City {get;组; }
public string Country {get;组; }
}

第2步:将报表查看器控件从工具箱拖到表单。


第3步:创建CustomReport.rdlc:右键单击>添加>添加新项>创建CustomReport.rdlc。


然后为它插入一个Customers表,如下所示:



第4步:在表单中,右键单击报表查看器控件>选择报表> CustomReport.rdlc


第5步:主窗体中的代码:

 public partial class Form1:表格
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender,EventArgs e)
{

List< Customers> list = new List< Customers>();
list = GetData();
reportViewer1.LocalReport.DataSources.Clear(); //清除报告
reportViewer1.LocalReport.ReportEmbeddedResource =" WinFormTest3.CustomReport.rdlc" ;; //使用.rdlc绑定reportviewer
ReportDataSource dataset = new ReportDataSource(" DataSet1",list); //设置数据源
reportViewer1.LocalReport.DataSources.Add(dataset);
dataset.Value = list;

reportViewer1.LocalReport.Refresh();
reportViewer1.RefreshReport(); //刷新报告
}

private List< Customers> GetData()
{
string constr = @" Server = VDI-V-LEZHA1 \ SQLEXPRESS; Database = MyDB; Trusted_Connection = Yes" ;;
使用(SqlConnection con = new SqlConnection(constr))
{
using(SqlCommand cmd = new SqlCommand(" SELECT * FROM customers"))
{
using(SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
列表< Customers> list = new List< Customers>();
客户customer = new Customers();
sda.Fill(dt);
foreach(dt.Rows中的DataRow行)
{
customer.CustomerId = row [" CustomerId"]。ToString();
customer.ContactName = row [" ContactName"]。ToString();
customer.City = row [" City"]。ToString();
customer.Country = row [" Country"]。ToString();
list.Add(customer);
}
返回清单;
}
}
}
}
}

> ;> 2.在打印预览中,它显示较少的页面,但在打印时会打印更多页面。


如果看到打印,请单击打印按钮页码大于数据页码。您可以将其更改为数据页码。


就像:



另请参阅以下文件:


如何:在Windows窗体中打印使用打印预览。


最好的问候,


Stanly



Could someone please assist here on below queries?

1.Print functionality using Local report/Report viewer is prining only single page.
Is there any way to print all pages?

when i print only one page is getting printed but on printed page it shows 1/6(total pages in report).

I have tried setting startPage property of deviceInfo to Zero but it didnt work for me.

2.On Print preview , it shows less pages but while printing it prints more pages.
E,g. If it showes total 3 pages on print preview ,on print actually it prints 6 pages.

解决方案

Hi Rajesh111,

>> 1.Print functionality using Local report/Report viewer is prining only single page. Is there any way to print all pages?

I'm not sure how do you write you code, I make a simple demo and please refer to it as below:

Step 1: Create a class:

class Customers
{
        public string CustomerId { get; set; }
        public string ContactName { get; set; }
        public string City { get; set; }
        public string Country { get; set; }
}

Step 2: Drag the report viewer control from toolbox to Form.

Step 3: Create CustomReport.rdlc: Right click>Add>Add new Item>create CustomReport.rdlc.

Then insert a Customers table for it just like:

Step 4: In Form, right click report viewer control >Choose Report>CustomReport.rdlc

Step 5: Code in Main Form:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            List<Customers> list = new List<Customers>();
            list = GetData();
            reportViewer1.LocalReport.DataSources.Clear(); //clear report
            reportViewer1.LocalReport.ReportEmbeddedResource = "WinFormTest3.CustomReport.rdlc"; // bind reportviewer with .rdlc
            ReportDataSource dataset = new ReportDataSource("DataSet1", list); // set the datasource
            reportViewer1.LocalReport.DataSources.Add(dataset);
            dataset.Value = list;

            reportViewer1.LocalReport.Refresh();
            reportViewer1.RefreshReport(); // refresh report
        }

        private List<Customers> GetData()
            {
                string constr = @"Server=VDI-V-LEZHA1\SQLEXPRESS;Database=MyDB;Trusted_Connection=Yes";
                using (SqlConnection con = new SqlConnection(constr))
                {
                    using (SqlCommand cmd = new SqlCommand("SELECT * FROM customers"))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                          cmd.Connection = con;
                          sda.SelectCommand = cmd;
                        DataTable dt = new DataTable();
                        List<Customers> list = new List<Customers>();
                        Customers customer = new Customers();
                        sda.Fill(dt);
                        foreach(DataRow row in dt.Rows)
                        {
                            customer.CustomerId = row["CustomerId"].ToString();
                            customer.ContactName = row["ContactName"].ToString();
                            customer.City = row["City"].ToString();
                            customer.Country = row["Country"].ToString();
                            list.Add(customer);
                        }
                        return list;
                        }
                    }
                }
            }       
    }

>>2.On Print preview , it shows less pages but while printing it prints more pages.

Click the print button, if you see the print page number is greater than data page number. You could change it to data page number.

Just like:

Also please refer to the following document:

How to: Print in Windows Forms Using Print Preview.

Best Regards,

Stanly


这篇关于使用本地报表报表查看器类打印Winforms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆