How to remove or hide the main tab section in Crystal Report Viewer (C#).
7 Answers
Omid's answer is correct, but you have to make sure to do that stuff after you have set the viewer's ReportSource. The version in my function below is a little more robust, and makes what's going on a little clearer, though I'm still not sure why doing that bit of magic to the TabControl's ItemSize and SizeMode make the tab bar go away.
// This is a method of a Form with one of these:
// CrystalDecisions.Windows.Forms.CrystalReportViewer
// This hides the tab control with the "Main Report" button.
public void hideTheTabControl()
{
System.Diagnostics.Debug.Assert(
crystalReportViewer1.ReportSource != null,
"you have to set the ReportSource first");
foreach (Control c1 in crystalReportViewer1.Controls)
{
if (c1 is CrystalDecisions.Windows.Forms.PageView)
{
PageView pv = (PageView)c1;
foreach (Control c2 in pv.Controls)
{
if (c2 is TabControl)
{
TabControl tc = (TabControl)c2;
tc.ItemSize = new Size(0, 1);
tc.SizeMode = TabSizeMode.Fixed;
}
}
}
}
}
Thanks.
In VB it should seem like this:
For Each c1 As Control In CrystalReportViewer1.Controls
If c1.GetType Is GetType(CrystalDecisions.Windows.Forms.PageView) Then
Dim pv As CrystalDecisions.Windows.Forms.PageView = c1
For Each c2 As Control In pv.Controls
If c2.GetType Is GetType(TabControl) Then
Dim tc As TabControl = c2
tc.ItemSize = New Size(0, 1)
tc.SizeMode = TabSizeMode.Fixed
End If
Next
End If
Next
Solution for CrystalDecisions.Web ReportViewer
Put a reference to jquery.js
in the page and paste this script:
<script type="text/javascript">
$(document).ready(function () {
$(".hideableFrame").hide();
});
Explanation
I found that "Main Tab" is placed inside a <tr>
with class="hideableFrame"
<tr class="hideableFrame" valign="bottom" height="28" style="display: table-row;">
<td>
<img width="5" height="5"
...
I could not work in a css
file, since style:display
is written on the element, so I wrote a script that changes the visibility to items marked as hideableFrame
.
Note: there are 4 -USELESS- elements with class="hideableFrame"
; this script will hide all of them.
I tried the solution of Emanuele Greco and it works but sometimes it isn't possible to add a reference in your code to jquery. Try this in your web page
<CR:CrystalReportViewer ID="CrystalReportViewer1"
runat="server"
CssClass="Report"
HasCrystalLogo="False"
HasSearchButton="False"
HasToggleGroupTreeButton="False"
HasZoomFactorList="False"
Height="100%" Width="100%"
meta:resourcekey="CrystalReportViewer1Resource1"
EnableDrillDown="False"
ReuseParameterValuesOnRefresh="True"
EnableToolTips="False" ToolPanelView="None" HasDrilldownTabs="False"
HasDrillUpButton="False" />
foreach (Control control in crystalReportViewer1.Controls)
{
if (control is CrystalDecisions.Windows.Forms.PageView)
{
TabControl tab = (TabControl)(CrystalDecisions.Windows.Forms.PageView)control).Controls[0];
tab.ItemSize = new Size(0, 1);
tab.SizeMode = TabSizeMode.Fixed;
tab.Appearance = TabAppearance.Buttons;
}
}