Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

printing the contents of controls

Posted on 2009-06-29
5
Medium Priority
?
279 Views
Last Modified: 2012-05-07
Hi Experts

In vb2008 express edition i have a datagridview which displays the contents of a query on an access database, what i want to do is select certain records(rows) from the datagridview and print them in the form of an invoice eg:

The DataGridView

CustomerName | ID    |  OrderNo |   Details           | Price        |  

smith                  001    601            Lawnmower      £89.99
smith                  001    602            Hedgetrimmer     £59.99
smith                  001    603            Spade                £12.99
_____________________________________________________________________
The Invoice

Customer Name         smith
ID                                001

OrderNo     Details                Price        

601             Lawnmower      £89.99
602             Hedgetrimmer     £59.99
603             Spade                 £12.99

                         
                     subtotal          _______
                     tax                 ________
                grand total          ________
________________________________________________________________

As i have shown above this code will need to be able to work out the subtotal, tax and a grand total.  
Hope somebody can help.
0
Comment
Question by:dizzycat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:DanJourno
ID: 24736322
Hi,

You can draw your own print document and send it to the printer.

Its a little complicated and you may use quite a bit of paper in the process, but its quite simple once you've done it a few times.

First, you need a command button (or similar) and here is the code for it:-
            Dim doc As New PrintDocument()

' I use these to track what row im currently on. They are global integers
            PrintRowPosition = 0
            PrintPageNo = 1

            AddHandler doc.PrintPage, AddressOf Me.PrintFunc

            Dim dlgSettings As New PrintDialog()
            dlgSettings.Document = doc

            If dlgSettings.ShowDialog() = DialogResult.OK Then
                doc.Print()
            End If
===========
Then you need "printfunc" which is called repeatedly until you set e.hasmorepages to false

    Private Sub PrintFunc(ByVal sender As Object, ByVal e As PrintPageEventArgs)
dim StartingRow as integer = PrintRowPosition
dim Rect as new Rectangle
for PrintRowPosition  = Startingrow to List1.rows.count-1
'Here, calculate the position of the cell you are drawing, and set the rect x, y, width and height to the correct sizes.
'work out if you've hit the bottom of the page by looking at the rect.bottom variable and comparing it with the e.Marginbounds.bottom.
'If you've reached the bottom, set e.hasmorepages to true, and then exit sub. It will be called again automatically to draw the next page.
'then call this to draw the text
                    e.Graphics.DrawString(CELL_TEXT, FONT, Brushes.Black, Rect)
next

e.hasmorepages = false
End sub

====

just keep a running total and draw it at the end of the report.

Sorry if the coding has bugs. I wrote it directly into EE instead of testing it in .net
0
 

Author Comment

by:dizzycat
ID: 24736622
I understand what you are doing here, although going through every cell getting its size and working out where to print it does seem very involved, but i will give it a go and get back to you.
0
 
LVL 5

Expert Comment

by:DanJourno
ID: 24736865
Just use the loop and work out the row position by doing TextHeight x RowNumber.

The list I use gives me the cell size, so when I print, i get the list to automatically expand the columns to fit all the text, then i take the cell size from that to ensure it all fits.
0
 

Author Comment

by:dizzycat
ID: 24737855
Hi again DanJourno

Would you have any idea how to be able to preview what was going to be printed ie use a printpreviewdialougebox
0
 
LVL 5

Accepted Solution

by:
DanJourno earned 1500 total points
ID: 24740360
Ive not had any experience of using printpreview. During development, I use a pdf printer to "print" into a PDF file and preview it there.

If you want to give the user PrintPreview functionality within the program, take a look at the PrintPreviewControl. I assume its in the standard toolbox.
Also, take a look at this website which gives some pointers:-
http://www.startvbdotnet.com/controls/printdialog.aspx

Hope that helps.
Dan
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question