ReportViewer - change toolbar?

Does anyone have any good ideas on how to change the toolbar for WinForms in the ReportViewer toolbar? That is, I want to remove some buttons and varius, but it looks like the solution is to create a new toolbar instead of changing the one that is.

For example, I had to remove the export to excel and did it like this:

// Disable excel export foreach (RenderingExtension extension in lr.ListRenderingExtensions()) { if (extension.Name == "Excel") { //extension.Visible = false; // Property is readonly... FieldInfo fi = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic); fi.SetValue(extension, false); } } 

A little trick, if you ask me .. To remove toolbars, a possible way was to iterate over the Control array inside the ReportViewer and change the Visible property to hide the buttons, but it gets reset all the time, so this is not good.

WHEN does MS come with a new version of btw?

+7
toolbar reportviewer rdlc
source share
8 answers

There are many properties that you can specify which buttons you want to see.

For example ShowBackButton , ShowExportButton , ShowFindControls , etc. Check them out in help , it all starts with "Show."

But you are right, you cannot add new buttons. To do this, you need to create your own toolbar.

What do you mean by the new version? Version 2008 SP1 already exists.

+3
source share

Yeap. You can make it a little harder. I had the task of adding more scale factors to increase the report. I did it as follows:

  private readonly string[] ZOOM_VALUES = { "25%", "50%", "75%", "100%", "110%", "120%", "125%", "130%", "140%", "150%", "175%", "200%", "300%", "400%", "500%" }; private readonly int DEFAULT_ZOOM = 3; //-- public ucReportViewer() { InitializeComponent(); this.reportViewer1.ProcessingMode = ProcessingMode.Local; setScaleFactor(ZOOM_VALUES[DEFAULT_ZOOM]); Control[] tb = reportViewer1.Controls.Find("ReportToolBar", true); ToolStrip ts; if (tb != null && tb.Length > 0 && tb[0].Controls.Count > 0 && (ts = tb[0].Controls[0] as ToolStrip) != null) { //here we go if our trick works (tested at .NET Framework 2.0.50727 SP1) ToolStripComboBox tscb = new ToolStripComboBox(); tscb.DropDownStyle = ComboBoxStyle.DropDownList; tscb.Items.AddRange(ZOOM_VALUES); tscb.SelectedIndex = 3; //100% tscb.SelectedIndexChanged += new EventHandler(toolStripZoomPercent_Click); ts.Items.Add(tscb); } else { //if there is some problems - just use context menu ContextMenuStrip cmZoomMenu = new ContextMenuStrip(); for (int i = 0; i < ZOOM_VALUES.Length; i++) { ToolStripMenuItem tsmi = new ToolStripMenuItem(ZOOM_VALUES[i]); tsmi.Checked = (i == DEFAULT_ZOOM); //tsmi.Tag = (IntPtr)cmZoomMenu; tsmi.Click += new EventHandler(toolStripZoomPercent_Click); cmZoomMenu.Items.Add(tsmi); } reportViewer1.ContextMenuStrip = cmZoomMenu; } } private bool setScaleFactor(string value) { try { int percent = Convert.ToInt32(value.TrimEnd('%')); reportViewer1.ZoomMode = ZoomMode.Percent; reportViewer1.ZoomPercent = percent; return true; } catch { return false; } } private void toolStripZoomPercent_Click(object sender, EventArgs e) { ToolStripMenuItem tsmi = sender as ToolStripMenuItem; ToolStripComboBox tscb = sender as ToolStripComboBox; if (tscb != null && tscb.SelectedIndex > -1) { setScaleFactor(tscb.Items[tscb.SelectedIndex].ToString()); } else if (tsmi != null) { if (setScaleFactor(tsmi.Text)) { foreach (ToolStripItem tsi in tsmi.Owner.Items) { ToolStripMenuItem item = tsi as ToolStripMenuItem; if (item != null && item.Checked) { item.Checked = false; } } tsmi.Checked = true; } else { tsmi.Checked = false; } } } 
+7
source share

Get the toolbar from the ReportViewer control:

 ToolStrip toolStrip = (ToolStrip)reportViewer.Controls.Find("toolStrip1", true)[0] 

Add new items:

 toolStrip.Items.Add(...) 
+5
source share

Another way would be to control the generated HTML at run time through javascript. It is not very elegant, but it gives you full control over the generated HTML.

+3
source share

I had this question for al ong time. I found the answer after a long tie, and the main source of kowledge that I used was this webpega: I would like to thank all of you by adding a code that allowed me to do this image with the result.

Instead of using the ReportViewer class, you need to create new classes, in my case I called it ReportViewerPlus, and it will look like this:

 using Microsoft.Reporting.WinForms; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Windows.Forms; namespace X { class ReportViewerPlus : ReportViewer { private Button boton { get; set; } public ReportViewerPlus(Button but) { this.boton = but; testc(this.Controls[0]); } public ReportViewerPlus() { } private void testc(Control item){ if(item is ToolStrip) { ToolStripItemCollection tsic = ((ToolStrip)item).Items; tsic.Insert(0, new ToolStripControlHost(boton)); return; } for (int i = 0; i < item.Controls.Count; i++) { testc(item.Controls[i]); } } } } 

You must add the button directly in the class constructor, and you can customize the button in your designer.

Here's a pic of the result, not perfect, but enough to go (safe link, I swear, but I can’t post my own photos, not enough reputation).

http://prntscr.com/5lfssj

If you look closely at the class code, you will see more or less how it works, and you can make your changes and make it possible to install it elsewhere in the toolbar.

Thank you for helping me in the past, hope this helps many people!

+1
source share

For VS2013 Web ReportViewer V11 (denoted as rv), the code below adds a button.

 private void AddPrintBtn() { foreach (Control c in rv.Controls) { foreach (Control c1 in c.Controls) { foreach (Control c2 in c1.Controls) { foreach (Control c3 in c2.Controls) { if (c3.ToString() == "Microsoft.Reporting.WebForms.ToolbarControl") { foreach (Control c4 in c3.Controls) { if (c4.ToString() == "Microsoft.Reporting.WebForms.PageNavigationGroup") { var btn = new Button(); btn.Text = "Criteria"; btn.ID = "btnFlip"; btn.OnClientClick = "$('#pnl').toggle();"; c4.Controls.Add(btn); return; } } } } } } } } 
+1
source share

Generally, you should create your own toolbar if you want to change it. Your button removal solution will probably work if that's all you need to do, but if you want to add your own, you probably should just bite the bullet and build a replacement.

0
source share

You can modify ReportViewer controls using the CustomizeReportToolStrip method. in this example, remove the page setup button, page layout button in WinForm

 public CustOrderReportForm() { InitializeComponent(); CustomizeReport(this.reportViewer1); } private void CustomizeReport(Control reportControl, int recurCount = 0) { Console.WriteLine("".PadLeft(recurCount + 1, '.') + reportControl.GetType() + ":" + reportControl.Name); if (reportControl is Button) { CustomizeReportButton((Button)reportControl, recurCount); } else if (reportControl is ToolStrip) { CustomizeReportToolStrip((ToolStrip)reportControl, recurCount); } foreach (Control childControl in reportControl.Controls) { CustomizeReport(childControl, recurCount + 1); } } //------------------------------------------------------------- void CustomizeReportToolStrip(ToolStrip c, int recurCount) { List<ToolStripItem> customized = new List<ToolStripItem>(); foreach (ToolStripItem i in c.Items) { if (CustomizeReportToolStripItem(i, recurCount + 1)) { customized.Add(i); } } foreach (var i in customized) c.Items.Remove(i); } //------------------------------------------------------------- void CustomizeReportButton(Button button, int recurCount) { } //------------------------------------------------------------- bool CustomizeReportToolStripItem(ToolStripItem i, int recurCount) { Console.WriteLine("".PadLeft(recurCount + 1, '.') + i.GetType() + ":" + i.Name); if (i.Name == "pageSetup") { return true; } else if (i.Name == "printPreview") { return true; } return false; ; } 
0
source share

All Articles