Solved

C# - How to print a ListView

Posted on 2008-06-17
8
8,924 Views
Last Modified: 2013-12-16
Hello,

I am trying to print the contents of a ListView in C#, using Visual C# Express. I have no idea where to start, but I can't seem to find any good articles that explain it well. How would I go about printing the contents of the ListView box, as it appears on the screen?

Also - is it possible to send the data to a OpenDocument Template, and have that printed so it is themed how I want? If that is possible, and relatively quick and easy, I would like to go that method, but I am not sure at the moment. If not, I am quite happy with just being able to print the contents of the ListView box.

Thanks.
0
Comment
Question by:dh-s
[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
  • 4
  • 3
8 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 21810602
PrintDialog prtDlg = new PrintDialog();
                    if (prtDlg.ShowDialog() == true)
                    {
                        prtDlg.PrintVisual(listview1, "ListView");
                    }
0
 

Author Comment

by:dh-s
ID: 21810792
HI gauthampj. I get the following errors when I try this. I tried it on a new project with a listBox (becuase they are easier to setup for a temp test). Using Windows XP SP2

Operator '==' cannot be applied to operands of type 'System.Windows.Forms.DialogResult' and 'bool'

'System.Windows.Forms.PrintDialog' does not contain a definition for 'PrintVisual' and no extension method 'PrintVisual' accepting a first argument of type 'System.Windows.Forms.PrintDialog' could be found (are you missing a using directive or an assembly reference?)

The exact code that I am using is...

            PrintDialog prtDlg = new PrintDialog();
            if (prtDlg.ShowDialog() == true)
            {
                prtDlg.PrintVisual(listBox1, "ListView");
            }

under the click event of a button that would initiate the print process, with a listBox that contains some items.
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 21810854
sorry ... change to
(prtDlg.ShowDialog() == DialogResult.Ok)
0
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 

Author Comment

by:dh-s
ID: 21810981
Thanks. That fixes one of the errors, but I still get an error with prtDlg.PrintVisual...

System.Windows.Forms.PrintDialog' does not contain a definition for 'PrintVisual' and no extension method 'PrintVisual' accepting a first argument of type 'System.Windows.Forms.PrintDialog' could be found (are you missing a using directive or an assembly reference?)

Any suggestions here? Thanks!
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 21821292
which version are u suing 3.5 ?
0
 
LVL 3

Accepted Solution

by:
Pigtor earned 500 total points
ID: 21823479
Check the following link
http://www.codeproject.com/KB/list/PrintableListView.aspx

I think this is what you are looking for.
0
 

Author Comment

by:dh-s
ID: 21837147
I am using version 3.5 of the .NET Framework, yes. Do I need to import anything to get it working?
0
 

Author Comment

by:dh-s
ID: 21837527
Pigtor: After a bit of fiddling, I managed to get a ListView to print using that particular link! Thanks heaps.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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