To change the ToolStrip
appearance to show just the Save button without drop-down, you can find the ToolStrip
of the ReportViewer
and then find the "export" button and remove the dropdown.
To show the save dialog to just allow saving PDF, attach an event handler to click event of the "export" button and show the save dialog using ExportDialog
method of the report viewer. You can find the PDF extension between extensions which return by ListRenderingExtensions()
method of the LocalReport
and pass it to ExportDialog
method to limit the dialog to just show PDF
extension.
Example 1
Paste this code in load event of your form and after loading the report, press save button. It will show a save dialog containing just PDF option for saving file:
var toolStrip = (ToolStrip)reportViewer1.Controls.Find("toolStrip1", true).First();
((ToolStripDropDownButton)toolStrip.Items["export"]).ShowDropDownArrow = false;
((ToolStripDropDownButton)toolStrip.Items["export"]).DropDownOpening += (obj, arg) =>
{
((ToolStripDropDownButton)obj).DropDownItems.Clear();
};
((ToolStripDropDownButton)toolStrip.Items["export"]).Click += (obj, arg) =>
{
var pdf = reportViewer1.LocalReport.ListRenderingExtensions()
.Where(x => x.Name == "PDF").First();
reportViewer1.ExportDialog(pdf);
};
Example 2
If you don't want to remove the dropdown arrow and just want it to show PDF option in drop down, use this code:
var toolStrip = (ToolStrip)reportViewer1.Controls.Find("toolStrip1", true).First();
((ToolStripDropDownButton)toolStrip.Items["export"]).DropDownOpening += (obj, arg) =>
{
var item = ((ToolStripDropDownButton)obj);
item.DropDownItems.Cast<ToolStripItem>().Where(x => x.Text != "PDF").ToList()
.ForEach(x => item.DropDownItems.Remove(x));
};