65.9K
CodeProject is changing. Read more.
Home

Hide Report Group Tree in WPF

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (1 vote)

Jun 7, 2011

CPOL
viewsIcon

29701

Hiding ReportGroupTree in WPF is a little bit tricky, as there is no simple property or method to do this.

Introduction Hiding ReportGroupTree in WPF is a little bit tricky, as there is no simple property or method to do this. Background In WinForms we have a property DisplayGroupTree to hide ReportGroupTree but in WPF I checked for this property DisplayGroupTree but all in vain. Using the code First of all, I used CrystalReportViewer in WindowsFormsHost:
<WindowsFormsHost>
   <crystal:CrystalReportViewer x:Name="rptViewer" />
</WindowsFormsHost>
and then I added a property in code behind:
public bool ShowGroupTree
{
    set
    {
          System.Windows.Forms.Control control = null;
          for (int i = 0; i < m_Viewer.Controls.Count; i++)
          {
              control = rptViewer.Controls[i];
              if (control is ReportGroupTree)
               {  //Hide the Group tree by default.
                   control.Visible = value;
                  continue;
               }
         }
    }
}
Now we just need to call this property i.e. ShowGroupTree, where to hide the ReportGroupTree. Points of Interest
System.Windows.Forms.Control control = null; 
This control variable must be of System.Windows.Forms.Control type, otherwise it will throw Exception, as rptViewer.Controls[i] will is not of System.Windows.Controls.Control type.