我使用gridview完成了应用程序 [英] I done application using gridview

查看:94
本文介绍了我使用gridview完成了应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Gridview完成了一个应用程序,并将数据保存在数据库中。在运行模式下,当我点击打印按钮所有要打印的数据时,我有打印按钮。



表示如何编写代码。

I done a application using Gridview and save the data in the database.in run mode i have print button when i click the print button all data to be printed.

for that how to write the code.

推荐答案

嗨亲爱的,



hi dear,

private void FxDatagried()
       {
           SqlConnection objConn1 = new SqlConnection("Data Source= Sql Server Name ;Initial Catalog= Database Name ;user id=sa; password=123;"); // Write you sql server database name and necessary option.

           string sql = "SELECT * FROM TableName ";
           SqlCommand cmd = new SqlCommand(sql, objConn1);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           objConn1.Open();
           da.Fill(dt);
           dataGridView.DataSource = dt;
           objConn1.Close();
       }

       private void FxPrint()
       {
           printDocument1.Print();
       }










private void printDocument1_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)
        {
            Bitmap bm = new Bitmap(this.dataGridView.Width, this.dataGridView.Height);
            this.dataGridView.DrawToBitmap(bm, new Rectangle(0, 0, this.dataGridView.Width, this.dataGridView.Height));
            e.Graphics.DrawImage(bm, 0, 0);
        }


在C#.NET 2.0中打印datagridview [ ^ ]

http://csharp.net-informations.com/datagridview/csharp-datagridview-printing.htm [ ^ ]


PrintDocument类的MSDN [ ^ ] 。有一个例子演示了这个用法。



基本上,框架提供的图形对象就像你用来在屏幕上绘制的图形对象一样。用它在虚拟纸上绘图。然后打印机生成该文件的真实副本。
Start with MSDN on the PrintDocument class[^]. There is an example that demonstrates the use.

Essentially, the framework provides a graphics object just like the one you use to draw on the screen. Use it to draw on a virtual sheet of paper. The printer then produces a real-world copy of that.


这篇关于我使用gridview完成了应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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