http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/dc9d3acf-ccf8-457f-ba31-ef09fb357aee/

On Feb 19, 3:57 pm, Laura <[email protected]> wrote:
> Thanks, that was a very handy examply you provided and it was helpful.
> I see now that I was simply opening a print preview window.
>
> My remaining problem is however that I need to select the entire
> contents of the datagridview to send to the print preview. How can I
> do this.
>
> me.datagridview.rows/ .columns/........ I need to get all rows and all
> cols including headers.
>
> Thanks,
> Laura
>
> On Feb 19, 3:01 pm, The_Fruitman <[email protected]> wrote:
>
>
>
> > How does your print preview dialog know what document to display in
> > the print preview?  The code you've listed here only tells the
> > computer to show the print preview window.
>
> >http://www.vb-helper.com/howto_net_print_and_preview.html
>
> > On Feb 19, 6:49 am, Laura <[email protected]> wrote:
>
> > > Hi,
> > > I need to be able to print the entire contents of a datagridview or
> > > even if you have to select/highlight the columns/rows to print.
>
> > > I have the printdialog, printdocument and a printpreviewdialog on the
> > > form already. I got some code from a friend to print but the code she
> > > gave me was for printing the contents of a listbox and while I've
> > > adjusted it a little, I know its not right.
>
> > > I've been looking it up online a bit and found a good few sample
> > > projects/code and all of them seem really complex - formatting the
> > > contents of every cell, etc.
>
> > > Here's the code I have so far anyway;
>
> > >     Private Sub PrintToolStripMenuItem_Click(ByVal sender As
> > > System.Object, ByVal e As System.EventArgs) Handles
> > > PrintToolStripMenuItem.Click
> > >         If Me.PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK
> > > Then
> > >             Me.PrintDocument1.Print()
> > >         End If
> > >     End Sub
>
> > >     Private Sub PrintDocument1_PrintPage(ByVal sender As
> > > System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
> > > Handles PrintDocument1.PrintPage
> > >         Dim x As Integer = e.MarginBounds.Left
> > >         Dim y As Single = e.MarginBounds.Top
> > >         Dim lineheight As Single = Me.DataGridView1.Font.GetHeight
> > > (e.Graphics)
> > >         For Each item As String In Me.DataGridView1.Rows
> > >             e.Graphics.DrawString(item, Me.DataGridView1.Font,
> > > Brushes.Black, x, y)
> > >             y += lineheight
> > >         Next
> > >     End Sub
>
> > >     Private Sub PrintPreviewToolStripMenuItem1_Click(ByVal sender As
> > > System.Object, ByVal e As System.EventArgs) Handles
> > > PrintPreviewToolStripMenuItem1.Click
> > >         PrintPreviewDialog1.ShowDialog()
> > >     End Sub
>
> > > Just to add, what happens when I run the project is if I hit the print
> > > button, the print dialog thing comes up, but I don't even have my
> > > laptop connected to a printer, and if I bring up the print preview
> > > thing, it has nothing to preview.
>
> > > I know the line for each item as string in me.datagridview1.rows
> > > probably isn't right is it?
>
> > > Any advice on what I need to do to get this code going??
>
> > > Thanks- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Reply via email to