473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Printing the entire contents of a datagridview

Hi,
I need to be able to print the contents of a datagrid view. I have the printdialog, printdocument and printpreview dialog controls put on my form.. Here is my code so far:

Expand|Select|Wrap|Line Numbers
  1. Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
  2.         If Me.PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  3.             Me.PrintDocument1.Print()
  4.         End If
  5.     End Sub
  6.  
  7.     Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
  8.         Dim x As Integer = e.MarginBounds.Left
  9.         Dim y As Single = e.MarginBounds.Top
  10.         Dim lineheight As Single = Me.DataGridView1.Font.GetHeight(e.Graphics)
  11.         For Each item As String In Me.DataGridView1.Controls
  12.             e.Graphics.DrawString(item, Me.DataGridView1.Font, Brushes.Black, x, y)
  13.             y += lineheight
  14.         Next
  15.     End Sub
  16.  
  17.     Private Sub PrintPreviewToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem1.Click
  18.         PrintPreviewDialog1.ShowDialog()
  19.     End Sub
I know the code under printdocument_printpage isn't right. But how do I get everything in the datagridview selected to send it to print? I don't want the user to have to go highlighting the datagridview.

Your help would be really appreciated.

Thanks
Feb 18 '09 #1
2 8216
Did you ever get this working. I have to do the same thing and can't get it to work. Any help would be appreciated.
May 10 '09 #2
SSED
1
i have one example like what you wanted it .. but i cant upload it here .. and i cant post a new topic .. :(
Jul 2 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Vince | last post by:
I have a generic page that I use for printing content, and it contains an iframe into which I put the url for the page to be printed. I dynamically size the iframe so that it correctly displays...
2
by: Sharon | last post by:
Hi All. Is there a way to print the content of DataGridView, Without using Graphics.DrawString on every row? Thanks, Sharon.
5
by: ComputerStop | last post by:
I am attempting to print a datagridview. I have not found any method that works successfully. Has any one been successful with this?
1
by: Silvester | last post by:
I need to drag drop & copy entire row contents from a Source databound datagridview to a Target unbound datagridview. Source is set to SelectionMode fullrowselect. I am not sure how to achieve...
7
by: Arne Beruldsen | last post by:
in vbnet2005 I have a datagridview. When the user clicks on a row...I would like the contents of certain cells to populate a textbox. To do this...i need to be able to refer to the row and...
1
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Any tips on how to print the data in a datagridview control?
7
devikacs
by: devikacs | last post by:
i am new to C# .net. i am trying to print the contents of a sql table on a form using datagridview. i've first printed the values of a select command on the datagridview. on clicking a button, the...
5
by: dwadish | last post by:
Hi guys, I am dwadish a beginer in vb.net programing language and i am doing a project about a medical shop, while the project need printing reports.I am using datagridview control for...
0
by: dotnet2005 | last post by:
Hi Toall , I want to explain you clearly , I am having some panels having some controls CheckBox,ComboBox,Datagridview,Hyperlink,label,Listbox,Picturebox,RadioButt­ on ,Textbox)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.