In the past few days, I have studied how to print the data in the datagridview C #, searched for and consulted some content on the Internet and in the library, and summarized it as follows:
// Execute the data operation in the print form
Private void toolstripbutton2_click (Object sender, eventargs E)
{
Printdialog1.showdialog (); // sets the Print Document
Printpreviewdialog1.document = This. printdocument1;
Printpreviewdialog1.showdialog ();
}
// Draw the data to be printed in the form
Private void printdocumentemediprintpage (Object sender, system. Drawing. Printing. printpageeventargs E)
{
// E. Graphics. drawstring (datagridview1.columns. tostring (), new font ("", 10, fontstyle. Regular), brushes. Black, 260,400 );
Int r = 0;
Int c = 20;
For (INT I = 0; I <DT. Rows. Count; I ++)
{
For (Int J = 0; j <DT. Columns. Count; j ++)
{
E. graphics. drawstring (DT. rows [I] [J]. tostring (), new font ("", 10, fontstyle. regular), brushes. black, R, C );
R = R + 60;
}
R = 0;
C + = 20;
}
}