Windows Develop Bookmark and Share   
 index > Windows Forms General > printing datagrid
 

printing datagrid

I have a datagrid that I want to print. I have added all the print stuff, but when my form prints I get only what is visible on the datagrid, which is about 25% of the entire result.

Here's my printing code:

private void printDoc_PrintPage(Object sender , PrintPageEventArgs e) 
{
PaintEventArgs myPaintArgs = new PaintEventArgs(e.Graphics, new Rectangle(0,0,dgcompare.Width, dgcompare.Height + 50));
this.InvokePaint(dgcompare, myPaintArgs);
}

private void menuItem3_Click(object sender, System.EventArgs e)
{
  printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
  printDoc.Print();


}
MigrationUser 1  Tuesday, January 28, 2003 8:38 AM
Well, since it's been 2 weeks and noone has taken a stab at this, hopefully you won't mind a very broad guess!

It looks like your code is just painting what is viewable on the form, almost like a screenshot. 

I know this is what you said it is doing, but that's what the code looks like it is TELLING it to do.

The screen does not "see" the rest of the data.

I have not done any direct printing in winforms to the printer. In VB6 (sorry, I know you are using C#), I did a bunch of things over the years where I printed directly to the printer, but in that case you would have to walk through the dataset and format on the way to the printer. What a drag if you have some nice formatting you have already done in the datagrid.

What about using a reporting tool? Crystal Reports is part of VS.Net Enterprise (maybe other levels, too?). There is Active Reports. There are probably a lot of other tools out, too. Create a report that formats your dataset just like the datagrid does and when you print, just shove the dataset into the report (set datasource)?

Just an idea....

julie lerman
MigrationUser 1  Thursday, February 13, 2003 10:42 PM
I'm not sure if you've already solved this problem or not, but here is an article that might help:

<a href="http://www.c-sharpcorner.com/Graphics/DataGridPrinterMG.asp">How to Print a DataGrid in C# and .NET</a>

HTH...

Chris
MigrationUser 1  Tuesday, February 25, 2003 3:04 PM

You can use google to search for other answers

Custom Search

More Threads

• Create Progreebar control in grid view control
• FileListBox shows the files extensions. A way to hide it?
• Memory leak when you use a solidbrush or pen to paint a control with a system color
• Show Explorer.exe without mininmize,maximize,close button
• ink desktop 2.0 not working in Vista
• native code
• System.Windows.Forms.Form -> StackOverflow
• Debug vs Release Mode: is vbc case sensitive?
• Check if Component is Unique
• Using Spy++ to Assist with Automated Testing