Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Every One,

I am working on a banking project where i need to print a pass Book for that i am getting all the printing records on DataGridview . Before giving print i am showing print preview . Here i want to print on pass book based on the columns in book that is i need to align the data that has to be printed on book.
I am doing this on windows form application.Here i am using printpreviewcontrol
in .net Even i am getting print preview as per my requirement but the thing is it s not getting printed. To check printer i typed some junk in word document and send to printer it is printing . Now the problem is in my code .Here is how i am writing code for printing

private void printDocument_PassBookDetails_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev)
    Font ObjFont = new Font("arial", 9, FontStyle.Bold);
    while (intPassBookStartLine < intPassBookEndLine)

                ev.Graphics.DrawString(DGV_Printing.Rows[intPassBookStartLine].Cells[0].Value.ToString(), ObjFont, Brushes.Black, 10, passbookStartLine);
                ev.Graphics.DrawString(DGV_Printing.Rows[intPassBookStartLine].Cells[6].Value.ToString(), ObjFont, Brushes.Black, 54, passbookStartLine);
                ev.Graphics.DrawString(DGV_Printing.Rows[intPassBookStartLine].Cells[3].Value.ToString(), ObjFont, Brushes.Black, 135, passbookStartLine);
                ev.Graphics.DrawString(DGV_Printing.Rows[intPassBookStartLine].Cells[7].Value.ToString(), ObjFont, Brushes.Black, 380, passbookStartLine);
                ev.Graphics.DrawString(DGV_Printing.Rows[intPassBookStartLine].Cells[4].Value.ToString(), ObjFont, Brushes.Black, 450, passbookStartLine);
                ev.Graphics.DrawString(DGV_Printing.Rows[intPassBookStartLine].Cells[5].Value.ToString(), ObjFont, Brushes.Black, 540, passbookStartLine);
                ev.Graphics.DrawString(DGV_Printing.Rows[intPassBookStartLine].Cells[8].Value.ToString(), ObjFont, Brushes.Black, 620, passbookStartLine);

                passbookStartLine += 20;
                intPassBookStartLine += 1;
//if it exceeds passbook region the next line must be printed in next page from starting point.
                if (passbookStartLine > 650)
                    passbookStartLine = 80;
                    ev.HasMorePages = true;
                    ev.HasMorePages = false;



Can anyone tell me actually whats wrong in code I am getting print preview as per my requirement but the thing is it is not printing.

If I hard code the data it is getting printed.

ev.Graphics.DrawString("29", ObjFont, Brushes.Black, 10, 680);
           ev.Graphics.DrawString("01/01/2013", ObjFont, Brushes.Black, 60, 680);
           ev.Graphics.DrawString("dgdfg cvbdf gdfgdfgd dfgdfg", ObjFont, Brushes.Black, 135, 680);
           ev.Graphics.DrawString("987654", ObjFont, Brushes.Black, 380, 680);
           ev.Graphics.DrawString("10000000", ObjFont, Brushes.Black, 450, 680);
           ev.Graphics.DrawString("24000000", ObjFont, Brushes.Black, 540, 680);
           ev.Graphics.DrawString("30000000", ObjFont, Brushes.Black, 620, 680);

Thanks in Advance,

Arun R.V
Updated 6-Jun-13 20:52pm
CHill60 7-Jun-13 5:37am    
What are the values in intPassBookStartLine and intPassBookEndLine?
Sunasara Imdadhusen 11-Jun-13 1:38am    
Are you getting any error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900