2
votes

I am using a ReportViewer and I would like to print my report.

When I click on the print button, a dialog box opens. It is similar to this.

excel print dialog box

I would like my program to skip this dialog and choose the default printer.

Is there a way to do one of the following things:

  • Just skip the dialog box
  • Map the print button to a function I wrote and that prints the report without showing the dialog box: something similar to myButton.Click += new EventHandler(myButton_Click);

I checked MSDN but found nothing to alter the default toolbar.


Edit: I did find this discussion from 2006, where an answer basically says that it is not possible. I guess that hiding the toolbar and creating my own would be a solution but it's a bit overkill.

UPDATE: This is not a duplicate. I know there is a question called "How to print a ReportViewer's report without showing a form", in which the guy wants to be able to choose between showing the form and printing the report. This is not my problem. I do want to display the form, and I want that when I click on the Print button, it prints the report, without asking me which printer to use.

1
Not possible as its a control you are using which has this functionality and nothing is exposed to print directly to the default printer. Only other way is to NOT use the report viewer and create your own control as suchAhmed ilyas

1 Answers

1
votes

I found a solution !

More precisely I found a workaround that enables you to call a custom printing function.

You need to use the Print event of the ReportViewer.

You can then catch the event, cancel it and call your own printing function:

myViewer.Print += new CancelEventHandler(myViewer_Print);
void myViewer_Print(object sender, CancelEventArgs e)
{
    e.Cancel = true;
    MyCustomPrintFunction();
}