Solved

Set printer in reportviewer

Posted on 2008-10-29
5
1,065 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

14 Experts available now in Live!

Get 1:1 Help Now