This is a migrated thread and some comments may be shown as answers.

PrintPreview Control select printer and suppress PrintDialog

5 Answers 466 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Wetzorke
Top achievements
Rank 1
Wetzorke asked on 16 Nov 2017, 11:29 AM

Hello,

I use the PrintPreview Control with the PrintAndExportExtensions.cs as shown in the GridView/PrintPreviewWithSpreadsheet example, which works very nicely.

Now I would like to suppress the Windows PrintDialog which is shown after clicking the print button, since it blocks the UI and does not show the parameters correctly (instead of the previously in the PrintPreview Control selected parameters the dafault values are displayed but it seems the correct values are pased to the printer).

For selecting the printer, I would like to add a ComboBox to my view. Is there a way to pass the selected printer as a string or with PrintSettings to the RadSheet or the PrintPreview Control/ViewModel and suppress the Windows PrintDialog?

I also had a look at the example from this post: https://www.telerik.com/forums/printing-and-print-previewing-my-grid#r3qTgvsrCkiSP_PxTMubzA

but the PrintSettings in the CreateDocument method aren't used.

Any help would be appreciated.

 

Best regards

5 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 21 Nov 2017, 10:59 AM
Hi Wetzorke,

Thank you for contacting us.

If I have understood you correctly you want to print silently the spreadsheet. To do that you can use the Print() method and its overloads. You can read more about this in the Printing help article in our documentation. Keep in mind that if you haven't visualized the  you need to use its Measure() and Arrange() methods before calling the Print() method.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Wetzorke
Top achievements
Rank 1
answered on 09 Feb 2018, 09:55 AM
Hello Dinko,

thanks for your reply. As you said, I used one of the Print() method's overloads and provided a PrintDialog to print the spreadsheet silently.

Unfortunately, the entered values for number of copies and page from/to are overwritten/ignored. I used your Just Decompile tool to check what the method actually does and I think all the information I provide in the PrintDialog are discarded.
Is there a way to suppress the dialog and keep the copy/from-to functionality?

Best regards
0
Dinko | Tech Support Engineer
Telerik team
answered on 14 Feb 2018, 09:41 AM
Hello Bernd,

If I have understood your approach correctly you want to preserve the PrintPreview and remove the default Windows PrintDialog. Indeed there is no straightforward approach which you can use to workaround this behavior. 

You can try achieving such scenario using custom code. I have modified the Print Preview With RadSpreadSheet SDK sample project which demonstrates how to print the RadGridView using PrintPreview functionality of the RadSpreadsheet control. What I have modified is subscribed to the Loaded event of the print preview window. In the event handler, I disable the default PrintDialog of the PrintPreview mechanism by setting the PrintCommand to Null. Then I have subscribed to the click event of the print button (use ChildrenOfType<T>() extension method to get the button). In the click event handler, I am creating custom PrintDialog which I am setting the PageOrientation, Copies, From to Page number, (other options are not applied, you can create custom code about them) depending on the user input. Then to print the page I am using the Print method of the RadSpreadsheet. Keep in mind that this is silent print and PrintDialog won't be showed. Also, the other options in the PrintPreview are not applied to the PrintDialog but you can use the ViewModel (PrintPreviewViewModel) property of the PrintPreviewControl which contains all options of the PrintPreview and set it manually to the PrintDialog. You can observe in the click event handler how the page orientation is set. 

However, keep in mind this is a custom solution and I cannot guarantee that it will work in all expected scenarios. This is why I recommend you to test it well and modify it so that it fits in your implementation.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Wetzorke
Top achievements
Rank 1
answered on 14 Feb 2018, 12:15 PM

Hello Dinko,

thanks for your help and the attached project.

The Copies function now works, but unfortunately the From to Page numbers are still ignored. My guess would be, that the

PageRange pageRange = new PageRange(1, this.PageLayout.PagesCount);

of the PrintManager.Print method overwrites the

printDialog.MinPage = uint.Parse(printPreview.ViewModel.FromPage.ToString());
printDialog.MaxPage = uint.Parse(printPreview.ViewModel.ToPage.ToString());

part of the attached code. I also tried to set the PageRange and the PageRangeSelection options of the PrintDialog but this didn't worked either.

To test the from to page functionality I altered the Club.GetClubs() method to this:

public static ObservableCollection<Club> GetClubs()
{
    ObservableCollection<Club> clubs = new ObservableCollection<Club>();
    Club club;
 
    // Liverpool
    club = new Club("Liverpool", new DateTime(1892, 1, 1), 45362);
    clubs.Add(club);
 
    // Manchester Utd.
    club = new Club("Manchester Utd.", new DateTime(1878, 1, 1), 76212);
    clubs.Add(club);
 
    // Chelsea
    club = new Club("Chelsea", new DateTime(1905, 1, 1), 42055);
    clubs.Add(club);
 
    // Arsenal
    club = new Club("Arsenal", new DateTime(1886, 1, 1), 60355);
    clubs.Add(club);
    for (int i = 0; i < 100; i++)
    {
        club = new Club($"Club {i}", new DateTime(1886, 1, 1), 60355);
        clubs.Add(club);
    }
 
    return clubs;
}

to generate enough clubs to fill three pages.

Do you have any suggestions, what else I could try to make the From to page option work again?

Best regards,

0
Dinko | Tech Support Engineer
Telerik team
answered on 19 Feb 2018, 10:27 AM
Hello Bernd,

Thank you for the additional information. 

I have further investigated this on my side and this behavior is related to a one which is already logged in our Feedback Portal. You can subscribe to the item in order to received notifications when the status is changed. At this moment I can't give you any workaround which you can use to set the page range.

Regards,
Dinko
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Wetzorke
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Wetzorke
Top achievements
Rank 1
Share this question
or