Solved

Set printer in reportviewer

Posted on 2008-10-29
5
1,066 Views
Last Modified: 2013-11-26
I have a windows form with a reportviewer element. I have a drop down populated with the printers installed. I would like the user to select the printer from the dropdown and when they click the print button have the correct printer selected in the print dialog box. Has anyone been able to set the printer this way?
0
Comment
Question by:dvonderburg
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:kdwood
ID: 22835744
Greetings dvon,

Why not use the Print Button that is already a part of the default toolbar of the ReportViewer control?  It already has the functionality that you described and required no extra coding.

Regards,

Keith
0
 
LVL 1

Author Comment

by:dvonderburg
ID: 22835833
Keith thank you for the response and good question.

The report I've created needs to go to a different printer other than the default. Most of my users have a different default printer setup in their windows and they have to select the printer manually each time they print my report. I want to store the printer name for my report and when the user clicks the print button make that printer be the selected printer.

Thank you,

Don
0
 
LVL 10

Accepted Solution

by:
kdwood earned 500 total points
ID: 22841944
Ok, I understand now.  Give this a try:


        Dim strOldPrinter As String

        Dim WshNetwork As Object

        Dim pd As New Printing.PrintDocument
 

        Try

            

            strOldPrinter = pd.PrinterSettings.PrinterName
 

            WshNetwork = Microsoft.VisualBasic.CreateObject("WScript.Network")
 

            WshNetwork.SetDefaultPrinter("Your Printer Name That You Want To Use")
 

            pd.PrinterSettings.PrinterName = "Your Printer Name That You Want To Use"
 

        Catch exptd As Exception
 

            WshNetwork.SetDefaultPrinter(strOldPrinter)
 

        Finally
 

            WshNetwork = Nothing

            pd = Nothing
 

        End Try

Open in new window

0
 
LVL 10

Expert Comment

by:kdwood
ID: 22841966
By the way,

You will want to do this prior to clicking the print button.  Maybe on the loading of the form that hosts the printviewer control or whatever event calls your specific report.

Regards,

Keith
0
 
LVL 1

Author Closing Comment

by:dvonderburg
ID: 31511349
Perfect, thank you. The only change I needed was to the line "Dim pd As New Printing.PrintDocument" to "Dim pd As New Drawing.Printing.PrintDocument".
0

Featured Post

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.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 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

13 Experts available now in Live!

Get 1:1 Help Now