You need to print the task in your hand.
It's good to win from Google. You can share it with me ~
How can I print the data in datagrid?
Http://forums.aspfree.com/archive/t-17107
Http://forums.aspfree.com/t17107/s.html
Using system; using system. collections; using system. componentmodel; using system. drawing; using system. drawing. printing; using system. data; using system. windows. forms; namespace hooooo. print {public class datagridprinter {private DataGrid; private printdocument; private pagesetupdialog; private printpreviewdialog; Public datagridprinter (DataGrid) {This. dataGrid = DataGrid; printdocument = new printdocument (); printdocument. printpage + = new printpageeventhandler (this. printdocument_printpage);} private void printdocument_printpage (Object sender, system. drawing. printing. printpageeventargs e) {int rowcount = 0; int colcount = 0; int x = 0; int y = 0; int rowgap = 20; int colgap = 5; int leftmargin = 50; font font = new font ("Arial", 10); font headingfont = new font ("Arial", 11, fontstyle. underline); font captionfont = new font ("Arial", 10, fontstyle. bold); brush = new solidbrush (color. black); string cellvalue = ""; if (DataGrid. datasource. getType (). tostring () = "system. data. datatable ") {rowcount = (datatable) DataGrid. datasource ). rows. count;} else if (DataGrid. datasource. getType (). tostring () = "system. collections. arraylist ") {rowcount = (arraylist) DataGrid. datasource ). count;} colcount = DataGrid. tablestyles [0]. gridcolumnstyles. count; // print captionif (DataGrid. captionvisible) {Y + = rowgap; X = leftmargin; E. graphics. drawstring (DataGrid. captiontext, captionfont, brush, x, y);} // print headings y + = rowgap; X = leftmargin; For (Int J = 0; j <colcount; j ++) {If (DataGrid. tablestyles [0]. gridcolumnstyles [J]. width> 0) {cellvalue = DataGrid. tablestyles [0]. gridcolumnstyles [J]. headertext; E. graphics. drawstring (cellvalue, headingfont, brush, x, y); x + = DataGrid. tablestyles [0]. gridcolumnstyles [J]. width + colgap ;}// print all rowsfor (INT I = 0; I <rowcount; I ++) {Y + = rowgap; X = leftmargin; for (Int J = 0; j <colcount; j ++) {If (DataGrid. tablestyles [0]. gridcolumnstyles [J]. width> 0) {cellvalue = DataGrid [I, j]. tostring (); E. graphics. drawstring (cellvalue, Font, brush, x, y); x + = DataGrid. tablestyles [0]. gridcolumnstyles [J]. width + colgap; y = Y + rowgap * (cellvalue. split (New char [] {'\ R',' \ n '}). length-1) ;}}string S = cellvalue; string F3 = cellvalue;} public printdocument getprintdocument () {return printdocument;} public void print () {try {pagesetupdialog = new pagesetupdialog (); pagesetupdialog. document = printdocument; pagesetupdialog. showdialog (); printpreviewdialog = new printpreviewdialog (); printpreviewdialog. document = printdocument; printpreviewdialog. height = 600; printpreviewdialog. width = 800; printpreviewdialog. showdialog ();} catch (exception e) {Throw new exception ("Printer error. "+ E. message );}}}}
If you want to print the lines and pages of a table, you can read the following section.Article:
How to print a DataGrid in C # And. net