Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set printer in reportviewer

Posted on 2008-10-29
5
Medium Priority
?
1,074 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:Don VonderBurg
[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
  • 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:Don VonderBurg
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 2000 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:Don VonderBurg
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

719 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