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

Print settings

11 Answers 265 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
Alex Dybenko
Top achievements
Rank 2
Alex Dybenko asked on 21 Oct 2016, 11:46 AM

Hi,

is it an easy way to save/load all print settings for PivotGrid?

Thanks

Alex

 

11 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 24 Oct 2016, 01:26 PM
Hi Alex,

Thank you for writing.

Currently, we are not having a persistence API of RadPivotGrid`s print settings. You can, however, save the property values of the RadPrintDocument and PivotGridPrintStyle instances.

A suitable place to perform this logic is the OnBeginPrint method of the RadPrintDocument  class. This way you will be sure that the saved values are always the newest reflecting the changes performed by the end users: 
// In your pivot form
private void PrintPivotGrid()
{
    RadPrintDocument document = new MyRadPrintDocument();
    document.DefaultPageSettings.Landscape = true;
    document.DefaultPageSettings.PrinterSettings.Copies = 2;
    document.AssociatedObject = this.radPivotGrid1;
 
    PivotGridPrintStyle style = new PivotGridPrintStyle();
    style.LayoutType = PivotLayout.Compact;
    this.radPivotGrid1.PrintStyle = style;
 
    RadPrintPreviewDialog dialog = new RadPrintPreviewDialog();
    dialog.Document = document;
    dialog.ShowDialog();
}
public class MyRadPrintDocument : RadPrintDocument
{
    protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
    {
        base.OnBeginPrint(e);
 
        PivotGridPrintStyle style = ((RadPivotGrid)this.AssociatedObject).PrintStyle;
        // Save settings from the print and style objects.
    }
}

I hope this information is useful. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
0
Alex Dybenko
Top achievements
Rank 2
answered on 25 Oct 2016, 07:16 AM

Hi Hristo,

Thanks! Perhaps you can also show me how to add Save button to print settings dialog, so I can use it to save settings?

Alex

 

0
Hristo
Telerik team
answered on 25 Oct 2016, 12:01 PM
Hello Alex,

Thank you for writing back.

You can create a new CommandBarButton and add it to any of the strips of the RadCommandBar control used by the RadPrintPreviewDialog:
RadPrintPreviewDialog dialog = new RadPrintPreviewDialog();
CommandBarButton saveBtn = new CommandBarButton();
saveBtn.Click += saveBtn_Click;
dialog.ToolCommandBar.Rows[0].Strips[0].Items.Add(saveBtn);
 
I hope this helps. Please let me know if you need further assistance.
Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Alex Dybenko
Top achievements
Rank 2
answered on 26 Oct 2016, 02:45 PM

Hi Hristo,

thanks, but is it possible to add button to Print settings dialog? See attached

 

Alex

 

 

0
Hristo
Telerik team
answered on 27 Oct 2016, 12:19 PM
Hello Alex,

Thank you for writing.

In order to add an additional button to the PrintSettingsDialog, you need to create a custom RadPrintPreviewDialog and override its OnShowPrintSettingsDialog method. Please check my code snippet below: 
public class MyRadPrintPreviewDialog : RadPrintPreviewDialog
{
    protected override void OnShowPrintSettingsDialog()
    {
        if (this.Document == null)
        {
            return;
        }
 
        Form dialog = this.Document.AssociatedObject.GetSettingsDialog(this.Document);
        RadForm radDialog = dialog as RadForm;
 
        RadButton print = radDialog.Controls["buttonPrint"] as RadButton;
        RadButton saveBtn = new RadButton() { Text = "MyBtn" };
        saveBtn.Parent = radDialog;
        saveBtn.Size = print.Size;
        saveBtn.Location = new Point(print.Location.X - print.Size.Width - 6, print.Location.Y);
        saveBtn.Click += saveBtn_Click;
 
        if (radDialog != null)
        {
            radDialog.ThemeName = this.ThemeName;
        }
 
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            this.Document.PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.AllPages;
            this.printPreviewControl.InvalidatePreview();
            this.GetType().BaseType.GetMethod("UpdatePageCount", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, new object[] { });
        }
    }
 
    private void saveBtn_Click(object sender, EventArgs e)
    {
        //...
    }
}

I am also sending you a screenshot showing the result on my end.

I hope this helps. Please let me know if you need further assistance.

Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Alex Dybenko
Top achievements
Rank 2
answered on 27 Oct 2016, 02:56 PM

Hi Hristo,

Exactly what I need! One more thing - changes on Print setting dialog are applied to RadPrintDocument after you press Print or Preview, is it possible to call buttonPreview_Click (whatever it called) from saveBtn_Click? So the idea that saveBtn will work like MS Word "Set as default" button: in saveBtn_Click i call buttonPreview_Click, dialog is closed, user get back to preview and then i call my method SavePrintSettings()

Thanks

Alex

 

0
Hristo
Telerik team
answered on 28 Oct 2016, 02:27 PM
Hello Alex,

Thank you for writing back.

There is no way to preview the changes without actually applying them to the document. I can suggest adding save logic at the end of the OnShowPrintSettingsDialog method. This way it will be always in sync with the printed or previewed document. Additionally, you may also consider adding the button in the command bar as I suggested in my second post.

In case that does not fit your project and you insist on using the separate button you can apply and save the changes this way: 
public class MyRadPrintPreviewDialog : RadPrintPreviewDialog
{
    Form dialog;
    protected override void OnShowPrintSettingsDialog()
    {
        if (this.Document == null)
        {
            return;
        }
 
        dialog = this.Document.AssociatedObject.GetSettingsDialog(this.Document);
        RadForm radDialog = dialog as RadForm;
 
        RadButton print = radDialog.Controls["buttonPrint"] as RadButton;
 
        RadButton saveBtn = new RadButton() { Text = "MyBtn" };
        saveBtn.Parent = radDialog;
        saveBtn.Size = print.Size;
        saveBtn.Location = new Point(print.Location.X - print.Size.Width - 6, print.Location.Y);
        saveBtn.Click += saveBtn_Click;
 
        if (radDialog != null)
        {
            radDialog.ThemeName = this.ThemeName;
        }
 
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            this.Document.PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.AllPages;
            this.printPreviewControl.InvalidatePreview();
            this.GetType().BaseType.GetMethod("UpdatePageCount", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, new object[] { });
        }
    }
 
    private void saveBtn_Click(object sender, EventArgs e)
    {
        typeof(PrintSettingsDialog).GetMethod("ApplySettings", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(dialog, new object[] { });
 
        this.Document.PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.AllPages;
        this.printPreviewControl.InvalidatePreview();
        this.GetType().BaseType.GetMethod("UpdatePageCount", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, new object[] { });
 
        //Execute your logic for saving the settings
 
        dialog.Close();
    }
}

I hope this helps. Please let me know if you need further assistance.

Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
0
Alex Dybenko
Top achievements
Rank 2
answered on 02 Nov 2016, 06:52 AM

Thanks Hristo, works great!

Alex

0
Sina
Top achievements
Rank 1
answered on 24 Jul 2018, 08:14 PM

Hi Hristo

Could you help me how to customize scheduler print setting dialog. i need to to change the culture of two calendars in print setting dialog(they have been highlighted in my attached file).

0
Hristo
Telerik team
answered on 25 Jul 2018, 06:10 AM
Hi Sina,

We try to keep our threads more or less focused on a single topic and this thread is discussing Print Settings in RadPivotGrid. Please open a new forum thread here or a support ticket from your Telerik account. Thank you for understanding.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Lina
Top achievements
Rank 1
answered on 11 Apr 2019, 06:05 AM
Very Helpful reply by Hristo. 
Tags
PivotGrid and PivotFieldList
Asked by
Alex Dybenko
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Alex Dybenko
Top achievements
Rank 2
Sina
Top achievements
Rank 1
Lina
Top achievements
Rank 1
Share this question
or