Vik Shah
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
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
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(DataGridVi ew1, printDocument1, DataTable1);
dataGridPrinter1.PageNumbe r = 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 ?
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(DataGridVi
dataGridPrinter1.PageNumbe
dataGridPrinter1.RowCount = 0;
if (printDialog1.ShowDialog()
{
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try out to use Microsoft Reporting Services.
It gives you a lot of flexibility and you don't need to paint it yourself.
It gives you a lot of flexibility and you don't need to paint it yourself.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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