Link to home
Start Free TrialLog in
Avatar of Vik Shah
Vik ShahFlag for United States of America

asked on

Print DataGridView

hi
I have a c# windows program which will query data from database, and show it on the dataGridView
I want to create a button so that I can click on the button to print the dataGridView or dataTable
how can I do that?

thanks
Avatar of vo1d
vo1d
Flag of Germany image

you will have to do all your drawing by yourself using the graphics object if a printdocument.
to get more information, which objects you need to get to the point, where you have to to your drawing, take a look at this link:
http://www.c-sharpcorner.com/winforms/texteditor.asp
Avatar of Vik Shah

ASKER

I check the link, I have a similar c# code sample from same editor (Michael Gold)
http://www.c-sharpcorner.com/Graphics/DataGridPrinterMG.asp
 I  look at the code, it uses DataGrid instead of DataGridView
and DataSet instead of DataTable. I modify the code to use DataGridView and DataTable.

The structure of my program is :
Several DataGridViews in a  windows form ,
Each of them has a DataTable as DataSource
Next to each view, there is a print button
the print button will call
            dataGridPrinter1 = new DataGridPrinter(DataGridView1, printDocument1, DataTable1);
            dataGridPrinter1.PageNumber = 1;
            dataGridPrinter1.RowCount = 0;
            if (printDialog1.ShowDialog() == DialogResult.OK)
            {
                printDocument1.Print();
            }

but when I try to preview or print, it only shows a blank page.

What could possibly go wrong?

Thanks a lot

By the way,  are you Michael Gold ?
SOLUTION
Avatar of vo1d
vo1d
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gena17
gena17

Try out to use Microsoft Reporting Services.
It gives you a lot of flexibility and you don't need to paint it yourself.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial