Hi,
is it an easy way to save/load all print settings for PivotGrid?
Thanks
Alex
11 Answers, 1 is accepted
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
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
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
Hi Hristo,
thanks, but is it possible to add button to Print settings dialog? See attached
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
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
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
Thanks Hristo, works great!
Alex
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).
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