Search code examples
c#.netwinformsreportviewertoolstrip

Moving the toolbar in ReportViewer to the bottom of the page


Relatively new to ReportViewer in WinForms using C#. What I want to do is to move the toolbar of a report to the bottom. One method to achieve this was supposedly to just drop a toolstrip on the page and build it from the toolbar. Seemed relatively easy, just a few lines of code inserted into the Load event:

// move the toolbar from the report viewer to the toolstripcontainer
ToolStrip toolStrip = (ToolStrip)FirstTestReport.Controls.Find("toolStrip1", true)[0];
toolStrip.GripStyle = ToolStripGripStyle.Hidden;
this.toolStripContainer1.TopToolStripPanel.Controls.Add(toolStrip);
this.FirstTestReport.ShowToolBar = false;
this.toolStripContainer1.Visible = true;

Sorta worked. So, the top toolbar disappeared, but the bottom one never appeared. While stepping through the code I realized ToolStrip always had a Visible value of False. I tried to add a line to make it visible (ToolStrip.Visible = True) but it didn't run the code; it gave me an error:

An object reference is required for the non-static field, method or property 'Control.Visible'

Any ideas on how to fix this?


Solution

  • With ToolStripContainer

    Also if you want it to be added to the bottom panel of the tool strip container:

    var toolStrip = (ToolStrip)reportViewer1.Controls.Find("toolStrip1", true)[0];
    toolStrip.GripStyle = ToolStripGripStyle.Visible;
    var reportToolbar = toolStrip.Parent;
    reportToolbar.Visible = false;
    this.toolStripContainer1.BottomToolStripPanel.Controls.Add(toolStrip);
    

    Without ToolStripContainer

    var toolStrip = (ToolStrip)reportViewer1.Controls.Find("toolStrip1", true)[0];
    toolStip.Parent.Dock = DockStyle.Bottom;
    

    Screenshot

    enter image description here