Click here to Skip to main content
15,906,626 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How to Print Data of GridView And Textboxes in Windows Forms<br />
Here is the code i tried,but it is taking screenshot but not able to print Scrollable Data:

Private Sub BtnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrint.Click
        Try
            If ComboOrderNo.SelectedIndex <> 0 And ComboShift.SelectedIndex <> 0 And TxtFromDate.Text <> "" And TxtToDate.Text <> "" Then
                Dim Printer = New DGVPrinter
                Printer.Title = "BOX HARDNESS ACCEPT REPORT"
                'Before printing, hide all Buttons
                Dim ctl As Control
                For Each ctl In Me.Controls
                    If ctl.GetType.FullName = "System.Windows.Forms.Button" Then
                        ctl.Visible = False
                    End If
                Next
                'Before printing, set Form.BackColor as White
                Dim FormBackColor As Color = Me.BackColor
                Me.BackColor = System.Drawing.Color.White
                Me.Refresh()
                'Printing the form
                Dim PF As New Microsoft.VisualBasic.PowerPacks.Printing.PrintForm
                PF.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
                'After printing, restore settings
                For Each ctl In Me.Controls
                    If ctl.GetType.FullName = "System.Windows.Forms.Button" Then
                        ctl.Visible = True
                    End If
                Next
                Me.BackColor = FormBackColor
            ElseIf ComboOrderNo.SelectedIndex = 0 Then
                MessageBox.Show("SELECT ORDERNO")
            ElseIf ComboShift.SelectedIndex = 0 Then
                MessageBox.Show("SELECT SHIFT")
            ElseIf TxtFromDate.Text = "" Or TxtToDate.Text = "" Then
                MessageBox.Show("GAVE FROM DATE/TO DATE")
            End If
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
    End Sub

<br />
Can any one suggest me <br />
<br />
"HOW TO PRINT 'SCROLLABLE DATA IN THE DATAGRIDVIEW' WITH THE 'TEXTBOXES-DATA' OUTSIDE THE DATAGRIDVIEW IN WINDOWS APPLICATION"<br />
I have been struggling with this from past 3 days,Please advise....
Posted
Updated 14-Jun-11 22:09pm
v9

If you want to do custom printing, then you need to do some research into the PrintDocument Class (MSDN)[^]. On the link I have provided is a good example of printing in .Net.

Hope this helps
 
Share this answer
 
Comments
midhunkumaralluru 14-Jun-11 7:04am    
I Gone through the Print Class,but it is not what i require.
I think you suggested, to print Data Exists in Text File.

But what i need is to print Data Exists in DataGridView & Data in Textboxes Outside the DataGrid.

Thanks For Reply!
Using PrintForm component in Visual Basic Power Packs

The PrintForm component is designed to bring back the ability to easily print a Windows Form. This makes it possible to layout the Windows Form exactly as you want and also allows you to print the form as a quick report.



Microsoft Visual Basic Power Packs 3.0 Download

[^]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
    Handles Button1.Click
    PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
End Sub

May this can fulfill your requirement
 
Share this answer
 
Comments
midhunkumaralluru 15-Jun-11 3:37am    
From 3 Days i have been trying to resolve to Print the data within the DatagridView Control & Textboxes outside the GridView in Windows Application.

Everypost suggesting about to capture the whole windows form as screenshot but can anyone suggest me,

HOW TO PRINT SCROLLABLE DATA INSIDE THE DATAGRIDVIEW & TEXTBOXES OUTSIDE THE DATAGRIDVIEW IN WINDOWS APPLICATION.
Karwa_Vivek 15-Jun-11 3:24am    
Have You tried the Visual Basic Power pack
midhunkumaralluru 15-Jun-11 3:38am    
Can you advice more...
What is Visual Basic Power Pack?
Karwa_Vivek 15-Jun-11 3:42am    
Please Visit the Provided Link in my Answer
to know about this .Your Google yourself.
It provides some more tools like print Forms
and other more advanced controls
For more Info on Visual Basic power pack
Visit this link .You will be most probably find your solution there
[^]
 
Share this answer
 
Comments
midhunkumaralluru 15-Jun-11 3:47am    
Can we able to print GridView Data With Text Boxes Data in Windows Application?
midhunkumaralluru 15-Jun-11 3:52am    
I gone through your link but it is taking screen shot of existing windows form.
But what i need is i have to print data in GridView which is scrollable & textboxes data.

I tried it,printing data in gridview but i am not succeed to print data with Textboxes outside the gridview.
Please suggest me! How to accomplish it.
Yeah!<br />
 Atlast i figured it out it won't be possible so i am now going to move to crystal reports to make it happen.<br />
  <br />
 Lesson:Don't give Up!Just try it there is always have a choice to make the things happen.
 
Share this answer
 
v3

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