Hi All,

I'm doing a mini project which is adding items to the listview and calculate the total price in a label outside the listview.

How do I print the final receipt with all the sold items listed and the total etc

Thanks in advance for ur help

How do I print a final receipt

Dani AI

Generated

Several practical options were already suggested in this thread. For a simple, printable receipt from the ListView the easiest, most controllable approach is to use a PrintDocument and draw the receipt lines yourself (as hinted by ). For a fully formatted invoice that needs page headers, totals, logos and export/preview features, a report (Crystal Reports or an RDLC/ReportViewer) is cleaner — as noted. For store-style thermal printers use a POS API/SDK (see ’s note).

A minimal, ready-to-adapt pattern is below: keep a module-level index so the PrintPage handler can continue across pages, draw columns at fixed X positions (or measure strings for dynamic columns), and use a monospaced font for easy alignment. This example assumes ListView1 in Details view and lblTotal holding the total.

Private printIndex As Integer = 0

Private Sub btnPreview_Click(sender As Object, e As EventArgs) Handles btnPreview.Click
    printIndex = 0
    Dim pd As New Printing.PrintDocument()
    AddHandler pd.PrintPage, AddressOf pd_PrintPage
    Dim preview As New PrintPreviewDialog()
    preview.Document = pd
    preview.ShowDialog()
End Sub

Private Sub pd_PrintPage(sender As Object, e As Printing.PrintPageEventArgs)
    Dim headerFont As New Font("Arial", 12, FontStyle.Bold)
    Dim itemFont As New Font("Courier New", 9)
    Dim left = e.MarginBounds.Left, right = e.MarginBounds.Right
    Dim y = e.MarginBounds.Top

    e.Graphics.DrawString("Store Receipt", headerFont, Brushes.Black, left, y)
    y += headerFont.Height + 8

    Dim xName = left, xQty = left + 220, xPrice = right - 80
    Dim sfRight As New StringFormat() With {.Alignment = StringAlignment.Far}

    For i As Integer = printIndex To ListView1.Items.Count - 1
        Dim it = ListView1.Items(i)
        Dim name = it.SubItems(0).Text
        Dim qty = If(it.SubItems.Count > 1, it.SubItems(1).Text, "")
        Dim price = If(it.SubItems.Count > 2, it.SubItems(2).Text, "")

        e.Graphics.DrawString(name, itemFont, Brushes.Black, xName, y)
        e.Graphics.DrawString(qty, itemFont, Brushes.Black, xQty, y)
        e.Graphics.DrawString(price, itemFont, Brushes.Black, New RectangleF(xPrice - 60, y, 60, itemFont.Height), sfRight)

        y += itemFont.Height + 3
        If y + itemFont.Height > e.MarginBounds.Bottom Then
            printIndex = i + 1
            e.HasMorePages = True
            Return
        End If
    Next

    y += 10
    e.Graphics.DrawString("Total: " & lblTotal.Text, itemFont, Brushes.Black, New RectangleF(xPrice - 60, y, 60, itemFont.Height), sfRight)
    e.HasMorePages = False
    headerFont.Dispose() : itemFont.Dispose()
End Sub

Notes and tips:

  • Test with PrintPreviewDialog first to tune column X positions and fonts.
  • Use Decimal.TryParse and FormatCurrency when drawing numeric totals.
  • For logos use e.Graphics.DrawImage at the top; for multi-page invoices consider RDLC/Crystal Reports and binding a DataTable of list items.
  • The ListBox trick from or converting the control to a bitmap can work for quick UI previews but have limits (scaling, pagination).

Recommended Answers

All 13 Replies

Hi. did you get a response on you wanting to print invoice etc. if so can you email me the code examples etc.

Thanks
<snip>

Hi all, i would like to do the same thing with vb.net as well? how should i do it? can someone please provide me guide on how to do this? do i have to start with crystal report? does anybody have tutorials on this?
please help... thanks in advance...

please everyone, can help me in this? thanks a lot... :) btw, i am new to this forum... let me intro myself, i am from malaysia...anyone heard bout this country??? heheh

Member Avatar for Member #46692

If you're looking for something that specifically prints out data in a crystal report style you'd be better of looking at a tutorial in a book rather than on the net as it will cover it in much more depth.

hie, thanks for the reply. i just wan to print the receipt, normal receipt... with those items and price where the user can enter from the form. the receipt may have the company logo or name and the data are located specifically in some page. must i do it in crystal report??? is there any crystal report book that you all recommend? which is easy and useful, thanks a lot :)

Member Avatar for Member #46692

That sounds very much like a crystal report.

There are entire books dedicated to crystal reports. But you'll want one which interfaces with vb.net and your database.

You can do something similar on the fly but getting all your data perfectly aligned etc will take a mammoth effort.

yo i amthwee, thanks a lot for da replies.
any recommended crystal report books? for newbie like me. :) i searched online and found many books, some have good and bad comments. so kinda confused on which book should i buy. Thanks in advance all.

Hi
I m having the same problem as u mentioned.
Can u Send me the code to my id
Its very urgent
Thanks in advance

hie all,
i still have no idea on how to do this, still can't find any tutorials on the net. please help...

Hi All,

I'm doing a mini project which is adding items to the listview and calculate the total price in a label outside the listview.

How do I print the final receipt with all the sold items listed and the total etc

Thanks in advance for ur help

How do I print a final receipt

Hi
i m facing the same problem as u mentioned.Can u send me the code to my Id .
Thanks in advance
Plz send me

Hi All,

I'm doing a mini project which is adding items to the listview and calculate the total price in a label outside the listview.

How do I print the final receipt with all the sold items listed and the total etc

Thanks in advance for ur help

How do I print a final receipt

I think, i also have the same problem.
I got an idea to acomplish this do it with a "list box",
but edit it on properties.
set the border style to NONE, and
BackColor to CONTROL.
By doing this when you execute the program it looks like part
of the report groupbox same backcolor.
From now just use Strings to add the book total.
if this helps and if the same assignment please upload
the code here.

Hi,
Why dont convert data to image format then print it. For example u have data in ListView Convert it to the PictureBox by using Graphics. Then u can print the image. Also Refer PrintDocument Control

Are you looking to use a receipt printer like they have at a store?

If so, use Microsoft.POS class. Google Microsoft POS SDK.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.