如何在多个页面上打印数据网格视图值 [英] How to print data grid view values at multiple pages

查看:83
本文介绍了如何在多个页面上打印数据网格视图值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am creating windows application using c# 2010 here I am using data grid view for reporting purpose, in my data grid view having above 100 rows, I want print multiple page my data grid view values I am write a code on printDocument1_PrintPage event handler, but data’s cannot shown on second page at print time 

how to print Data grid view values at multiple pages

this is my code any one give me just ideas

private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
 
            try
            {
 
                Graphics graphic = e.Graphics;
                e.PageSettings.PaperSize = new PaperSize("A4", 850, 1100);
                float pageWidth = e.PageSettings.PrintableArea.Width;
                float pageHeight = e.PageSettings.PrintableArea.Height;
                Font font = new Font("Times New Roman", 10, FontStyle.Bold);
 
                float fontHeight = font.GetHeight();
                int startX = 40;
                int startY = 30;
                int offsetY = 40;
 

                System.Drawing.Font fntString = new Font("Times New Roman", 10, FontStyle.Bold);
                System.Drawing.Font fnthead = new Font("Arial", 20, FontStyle.Bold);
 

                while (s < gvpurchase.Rows.Count)
                {
 

                    if (s % 2 == 0)
                    { 
 
                        for (; s <= 100; s++)
                        {
 
                            offsetY += (int)fontHeight;
 
                            if (offsetY >= pageHeight)
                            {
                                e.HasMorePages = true;
                                offsetY = 0;
                                return;
 

 
                                e.Graphics.DrawString(gvpurchase.Rows[s].Cells[2].Value.ToString(), fntString, Brushes.Black, 70, (s * 93) + 20);
                                e.Graphics.DrawString(gvpurchase.Rows[s].Cells[3].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 20);
                                e.Graphics.DrawString(gvpurchase.Rows[s].Cells[4].Value.ToString(), fntString, Brushes.Black, 70, (s * 93) + 40);
                                e.Graphics.DrawString(gvpurchase.Rows[s].Cells[5].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 40);
                                e.Graphics.DrawString(gvpurchase.Rows[s].Cells[6].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 60);
                                e.Graphics.DrawString(gvpurchase.Rows[s].Cells[7].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 80);
                                e.Graphics.DrawString(gvpurchase.Rows[s].Cells[8].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 100);
                                e.Graphics.DrawString(gvpurchase.Rows[s].Cells[9].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 120);
                                e.Graphics.DrawString(gvpurchase.Rows[s].Cells[10].Value.ToString(), fntString, Brushes.Black, 100, (s * 93) + 140);
 
                            }
 
                            else
                            {
                                e.HasMorePages = false;
                            }
 

                        }
 
                    }
 

 

 
                    else
                    { 
 

                        e.Graphics.DrawString(gvpurchase.Rows[s].Cells[2].Value.ToString(), fntString, Brushes.Black, 370, ((s - 1) * 93) + 20);
                        e.Graphics.DrawString(gvpurchase.Rows[s].Cells[3].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 20);
                        e.Graphics.DrawString(gvpurchase.Rows[s].Cells[4].Value.ToString(), fntString, Brushes.Black, 370, ((s - 1) * 93) + 40);
                        e.Graphics.DrawString(gvpurchase.Rows[s].Cells[5].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 40);
                        e.Graphics.DrawString(gvpurchase.Rows[s].Cells[6].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 60);
                        e.Graphics.DrawString(gvpurchase.Rows[s].Cells[7].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 80);
                        e.Graphics.DrawString(gvpurchase.Rows[s].Cells[8].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 100);
                        e.Graphics.DrawString(gvpurchase.Rows[s].Cells[9].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 120);
                        e.Graphics.DrawString(gvpurchase.Rows[s].Cells[10].Value.ToString(), fntString, Brushes.Black, 400, ((s - 1) * 93) + 140);
 
                       
                    }
 
                }
 
                s++;
 
            }
 
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
 

        }





我的尝试:





What I have tried:

How to print data grid view values at multiple pages

推荐答案

推荐链接这可能会对你有所帮助。



使用分页打印GridView [ ^ ]
Refer link this may help you.

Printing a GridView with Paging[^]


这篇关于如何在多个页面上打印数据网格视图值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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