Solved

C# - How to print a ListView

Posted on 2008-06-17
8
8,530 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
  • 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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now