i am stuckin the printing the listview items.i have already displayed in the listview.i would like to printpreview and also print it.
please help people.

Recommended Answers

All 13 Replies

you have to use




All printings in .Net are done using the PrintDocument class. Basically, you will handle the PrintDocument.PrintPage event and write your code there using GDI+ to draw the page. When you want to print, you just call the Print method of your PrintDocument object. Whether you're printing a picture, a text page or a listview is not important. The principles are the same. You will get the paper size, the margins and calculate your print area. You also calculate the x, y cordinates of each item being printed. It's not simple in my opinion, but it's not too difficult either.

You can find an example, here.

Send all the listview items to a DataSet then use the Microsoft Reportviewer to print

Use the PrintDcoument class or

Use the PrintDcoument class or

Hi chibex64,

That's the same what I suggested, but still waiting his response :icon_confused:

I am sorry for taking long to respond to your help.Thanks a lot Luc001,Chibex64, Aldeene and Pocohontus.i have made some progress and i am capable of printing and priviewing in richtextbox only but for listview i get a blank page.could you help me do it.attached here is an example.

any one of anymore assistance please?

As far as I can see, the preview is returning a blank page, because the line

Dim strText As String = Me.ListView1.Text

returns an empty string, as expected because you never filled his text propery.

Probably you should need to do some thing like

Dim strText as String
For Each lvi as ListViewItem in me.ListView1
    For Each lvsi as ListViewSubItem in lvi
        strText &= lvsi.Text & ControlChars.Tab
    strText &= ControlChars.CrLf

Hope this helps

Thanks alot lolafuertes for the assistance.i can see great sense in your code.i got one problem.the listview1 has an error."Expression is of type 'system.windows.forms.form.lisview 'which is not a collection type."could you further assist.thanks in advance.

in me.ListView1.Items :)

For Each lvi as ListViewItem in me.ListView1.Items


[I]For Each lvsi As [I][B][U]ListViewSubItem[/U][/B][/I] In lvi[/I]

thanks that worked but has also some syntax error in the above bolded position.

OOps. Too early in the morning ( or late in the night )

Please, be so kind to mark this thread ad solved.

Thanks in advance

Be a part of the DaniWeb community

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