打印网格视图列 [英] printing grid view columns

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

问题描述

你好

我想打印数据网格视图.我不知道该怎么做.

Hello

I want to print data grid view. I have no idea how to do it.

Please some body help me.

推荐答案

您最好的选择始终是格式化和打印数据源中的数据,而不是尝试打印控件.
Your best bet is always to format and print the data from your data source, not trying to print a control.


Hej Mate

希望我了解您在印刷方面的需求.我找到了一个链接,希望对您的任务有所帮助:
http://www.xmlfox.com/print_datagridview.htm

如果此链接不起作用,请尝试根据您的要求维护代码.
Hej Mate

I hope that I understand your needs on the printing concern. I have found a link which I hope will be helpful for your task:
http://www.xmlfox.com/print_datagridview.htm

If this link is not functioning, try to maintain the code up on your requirement.
private DataGridViewPrint PrintGrid;
private void btnPrint_Click(object sender, System.EventArgs e)
{
frmPrint fpr = new frmPrint();
fpr.Title = DataGridView1.CaptionText;
fpr.ShowDialog();
if (fpr.Result > 0)
{
PrintGrid = new DataGridViewPrint(printDocument1, DataGridView1, fpr.bBlackWhite);
PrintGrid.PrintTitle = fpr.bTitle;
PrintGrid.Title = fpr.Title;
if (fpr.Result == 1) // Print
{
if (printDialog1.ShowDialog() == DialogResult.OK)
{
// The Print method prints the DataGridView without using a print dialog.
// Use a PrintDialog when you want to offer the user the ability to choose print settings.
printDocument1.Print();
}
}
else if (fpr.Result == 2) // Page setup
{
pageSetupDialog1.ShowDialog();
}
else if (fpr.Result == 3) // Preview
{
printPreviewDialog1.Icon = fpr.Icon;
printPreviewDialog1.ShowDialog();
}
}
}
// Specify the output to print by handling the PrintPage event 
// and by using the Graphics included in the PrintPageEventArgs.
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
// Print method of DataGridViewPrint class starts the custom DataGridView's printing process.
e.HasMorePages = PrintGrid.Print(e.Graphics);
}


祝你好运


good luck


在过去,我记得使用过将代码转换DataGridView到HTML文件的代码,然后可以将其嵌入WebBrowser控件并进行打印.它运行得很完美,尽管我再也找不到了.而是尝试使用此另一台DataGridView打印机 [
In the past, I remember using a code that would transform a DataGridView into a HTML file that could then be embedded in WebBrowser control and printed. It worked flawlessy, though I can''t find it anymore. Instead, try using this Another DataGridView Printer[^].


这篇关于打印网格视图列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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