如何直接打印datagridview? [英] How do I print a datagridview directly?

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

问题描述

正如标题所说,我希望打印出一个datagridview,它具有与当前显示的完全相同的布局和格式(粗体,字体大小等),我还希望它将每个特定行数与每个页面分开打印。



假设datagridview与任何其他数据源无关,它基本上具有通用数据,但具有一定的布局,如何打印?我已经尝试并尝试了谷歌的各种代码,但无济于事,一切似乎从数据集/数据表中获取信息等。



这对我来说真的是一个问题现在,因为无法打印报告使得复制无用,我似乎无法找到在硬拷贝上正确显示这些信息的可靠方法。



使用我发现的基本打印文档命令也没有用,例如,http://csharp.net-informations.com/datagridview/csharp-datagridview-printing.htm



遗漏了我的第二列的一部分和整个第三列和几行(可能它不适合页面?)任何有关如何实现这一点的帮助将非常感激,无论是否它以某种方式将它移动到一个reportviewer或将其数据传输到datatables或我必须做的任何事情,基本上打印出datagridview完全如图所示,谢谢。

解决方案

我想在下面的陈述中争论:根据您提供的信息,问题在抽象层面没有很好的解决方案。这种解决方案既可以是通用的,但在许多情况下会产生丑陋的外观,或者如果基于某些分支,它看起来会很好,但不适合所有情况。



At同时,问题可能在您的应用程序层面得到很好的解决;你只需要做出假设,而不是试图使解决方案具有普遍性。但是您没有提供有关您的应用程序的足够信息,因此您必须自己处理它。请看我对这个问题的评论。



一个通用的解决方案就是:http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.printing.printform.aspx [ ^ ]。br />


另一个是:表格打印控制 [ ^ ]。



如果您阅读文章,您也可以使用这些想法并做一些接近您需求的事情。



所以,为什么通用解决方案不够好?这很简单。因为纸张不是屏幕而不是交互式。在窗口窗体中,您总是有 DataGridView 滚动,并且可以添加窗体调整大小和缩放和/或平移。这些都不适用于纸张。基本的数据可能不适合。



通常,从UI控件打印不是最好的主意。更高级和常规的想法是使用数据源进行打印。



-SA


转换它使用CSS(着色)与您的表格进入HTML页面并使用WebBrowser控件进行打印。 WebBrowser具有打印功能。



要将数据拆分为多个页面,只需测量页面可以分配的总行数,然后手动将表格分成多个表格。

As the title says, I wish to print out a datagridview with the same exact layout and format(bold,font sizes etc) that it currently shows, I also want it to separate every specific number of rows from every page that it prints.

Assume that the datagridview is unrelated to any other datasource and it basically has generic data but with a certain layout, How do I print this? I've tried and experimented on various codes from google but to no avail, everything seems to take information from datasets / datatables etc.

This is really an issue for me right now, as not being able to print out the report renders the aopplication useless, and I can't seem to find a solid way of just showing this information properly on a hard copy.

Using basic Print Document commands that I've found have also not worked, for example, http://csharp.net-informations.com/datagridview/csharp-datagridview-printing.htm

left out a part of my second column and the entire 3rd column and several rows ( perhaps it wasn't fit to page?) Any help on how to accomplish this would be greatly appreciated, whether it be somehow moving it to a reportviewer or transfering its data to datatables or anything that I must do to basically print out the datagridview exactly as its shown, Thank you.

解决方案

I want to argue on the following statement: the problem does not have good solution at the level of abstraction based on the information you provided. Such solution could be either universal but produce ugly look in many cases, or it would look good enough if based on some assuptions, but would not fit all cases.

At the same time, it's possible that the problem is well solvable at the level of your application; you would only need to make assumptions instead of trying to make the solution universal. But you did not provide enough information on your application, so you have to deal with it by yourself. Please see my comment to the question.

One universal solution is this: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.printing.printform.aspx[^].

Another one is this: Form Print Control[^].

You can also use the ideas and do something close to your needs if you read the article.

So, why the universal solution is not good enough? This is simple. Because paper is not screen and not interactive. In a window form, you always have DataGridView scrolling, and can add form resize and zoom and/or pan. None of that would work for paper. The data, elementary, may not fit.

Generally, printing from UI controls is not the best idea. More advanced and regular idea is to print using the data source.

—SA


Convert it into HTML page with CSS (colouring) with your table and print it by using WebBrowser control. WebBrowser has a print function.

To split the data into multiple pages, just measure the total lines that a page can allocate, then manually separate the table into multiple tables.


这篇关于如何直接打印datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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