打印datagridview中显示的数据 [英] print the data displayed in datagridview

查看:52
本文介绍了打印datagridview中显示的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有datagridview,它正在显示数据库中的数据.
我要打印完整的数据.
我的代码是:

I have datagridview which is displaying teh data from database .
I want take a print of that complete data .
My code is :

private void button3_Click(object sender, EventArgs e)
        {
            PrintDialog printDialog = new PrintDialog();
            printDialog.ShowDialog();

            printDialog1.AllowSomePages = true;

            // Show the help button.  
            printDialog1.ShowHelp = true;


            printDialog1.Document = docToPrint;
            DialogResult result = printDialog1.ShowDialog();

            // If the result is OK then print the document.       
            if (result == DialogResult.OK)
            {
                this.printDocument1.Print();
            }
        }
        private void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            string text = "In document_PrintPage method.";
            System.Drawing.Font printFont = new System.Drawing.Font

                ("Arial", 35, System.Drawing.FontStyle.Regular);
            e.Graphics.DrawString(text, printFont,
            System.Drawing.Brushes.Black, 10, 10);
 }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewCheckBoxCell chkcell = dataGridView1[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
            if (chkcell != null)
            {
                columnsToPrint[dataGridView1.CurrentRow.Index] = Convert.ToBoolean(chkcell.EditedFormattedValue);
            }

            if (dataGridView1.RowCount > 5)
            {
                //MessageBox.Show("There are a maximum of 31 days in a month buddy");
                dataGridView1.AllowUserToAddRows = false;
            }
        }
        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            Bitmap bm = new Bitmap(this.dataGridView1.Width, this.dataGridView1.Height);
            dataGridView1.DrawToBitmap(bm, new Rectangle(0, 0, this.dataGridView1.Width, this.dataGridView1.Height));
            e.Graphics.DrawImage(bm, 0, 0);

        }


此代码有效,但仅显示屏幕截图类型,这意味着在当前大小下可见的数据.....而不是整个数据.

请回复

meenakshi


This code is working but it will display only the screenshot type means data that is visible at current size.....not the whole one.

pls reply

meenakshi

推荐答案

hi http://csharpdotnetfreak.blogspot.com/2012/07/print-gridview-data-in-aspnet-c-vb.html [ http://indepthdotnet.blogspot.in/2011/06/java- script-function-for-printing-div.html [ ^ ]
试试这个
很简单
hi http://csharpdotnetfreak.blogspot.com/2012/07/print-gridview-data-in-aspnet-c-vb.html[^]

http://indepthdotnet.blogspot.in/2011/06/java-script-function-for-printing-div.html[^]
try this
it is simple




您可以从数据中生成HTML报告.

请参考 HTML报告引擎 [
Hi,

You can generate HTML report out from your Data.

Please Refer The HTML Report Engine[^]

Or you can manually create HTML table to generate your report out from your DataSource.

Thanks
-Amit Gajjar


这篇关于打印datagridview中显示的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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