Solved

C# - How to print a ListView

Posted on 2008-06-17
8
8,678 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

831 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