Hello, Iam tryin to find simple code that printing the datagridview. iv'e looked over the internet (also daniweb) i was founded only looooooongs codes or codes that print white pages. Please, anyone, help! i just want to print All the data in the datagridview (without any selected rows or something like that, just ALL).

8 Years
Discussion Span
Last Post by jatin24

Use printDocument Control.

Add the 'Print Document' and 'Print Dialog' control to the form. Then for the PrintPage event handler of the PrintDcoument control you can use something like this:

Font f = new Font("Arial",14,FontStyle.Regular);
            Brush b = Brushes.Black;
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                for (int j = 0; j < dataGridView1.Columns.Count; j++)
                    e.Graphics.DrawString(dataGridView1(i,j) + "    ", f, b, j*5, i*5);

Create another button, name it Print or whatever you like. On the Click event of that button, call the use the PrintDialog control and assign this print document object to that print dialog.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.