Problem getting the ReportViewerModel after upgrade to Q1'11

10 posts, 0 answers
  1. Paolo
    Paolo avatar
    403 posts
    Member since:
    Jun 2009

    Posted 16 Mar 2011 Link to this post

    Hello,
    before I was getting the ReportViewerModel doing so :

    var reportViewerModel = reportViewer.DataContext as ReportViewerModel;

    Today after Q1'11 upgrade I get an Enum I define in the Main page hosting it.... why this happen?
    Thanks

  2. Chavdar
    Admin
    Chavdar avatar
    893 posts
    Member since:
    Sep 2012

    Posted 16 Mar 2011 Link to this post

    Hello Paolo,

    This change is done on purpose in order to allow binding of report viewer properties directly to an inherited DataContext (see the release notes). If you have to get the ReportViewerModel then you should use the report viewer's first child instead. Here is a sample code snippet which shows how to achieve this:

    var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);
    var rvm = (ReportViewerModel)(layoutRoot.DataContext);

    This works both for WPF and Silverlight report viewers.

    However the ReportViewerModel in both Silverlight and WPF report viewers is intended for internal use by the controls and we will appreciate if you share with us your particular case that demands the use of the ReportViewerModel.

    All the best,
    Chavdar
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

  3. DevCraft Release
  4. PCF
    PCF avatar
    5 posts
    Member since:
    Mar 2011

    Posted 11 May 2011 Link to this post

    Hello,
    If it's similar to the use case I'm in right now, we need a way to refresh the report using parameters that can only be set from outside of the ReportViewer...and we're using Silverlight MVVM.

    The previous version allowed you to do this, and it worked quite well:

    ((ReportViewerModel)this.InvoiceReportViewer.DataContext).RefreshReportCommand.Execute(null);

    Now, as you mentioned, that breaks.
    The issue with the work-around now is that my report does not have a child and the call to GetChild(ReportViewer, 0) now breaks with this error:
    Specified argument was out of the range of valid values.
    Parameter name: childIndex

    I don't want to un-upgrade all the reports but that's what I'll have to do I guess...

  5. Steve
    Admin
    Steve avatar
    10942 posts
    Member since:
    May 2014

    Posted 16 May 2011 Link to this post

    Hi PCF,

    Here is a working sample snippet tested on our demos that illustrates this approach:

    Copy Code
    Copy Code
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
     
        void button1_Click(object sender, RoutedEventArgs e)
        {
            this.ReportViewer1.RefreshReport();
        }
    }
     
    static class ReportViewerExtensions
    {
        public static void RefreshReport(this ReportViewer reportViewer)
        {
            var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(reportViewer, 0);
            var viewerModel = (ReportViewerModel)layoutRoot.DataContext;
            var refreshCommand = viewerModel.RefreshReportCommand;
            if (refreshCommand.CanExecute(null))
            {
                refreshCommand.Execute(null);
            }
        }
    }

    Hope it helps.

    Regards,
    Steve
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

  6. Andrew Smith
    Andrew Smith avatar
    4 posts
    Member since:
    Nov 2009

    Posted 16 May 2011 Link to this post

    I was using this to hide the parameters area.

     If e.PropertyName = "IsParametersAreaVisible" _
        AndAlso CType(reportv.DataContext, ReportViewerModel).IsParametersAreaVisible _
        AndAlso m_bOverwriteReportParameters Then


          CType(reportv.DataContext, ReportViewerModel).IsParametersAreaVisible = False
          m_bOverwriteReportParameters = False
        End If


  7. Anton Swanevelder
    Anton Swanevelder avatar
    26 posts
    Member since:
    Aug 2008

    Posted 31 May 2011 Link to this post

    Hi,

    I am trying to make sense of how MVVM fits into the Silverlight ReportViewer but I am just too unfamiliar with Telerik Reports to make any sense of it.

    I've logged a support ticket under my account regarding, but this article seems that you are saying that the DataContext will inherit in Silverlight.

    Am I suppose to create the Report with an Objectdatasource or without, any nice walkthroughs on this just simply explaining ReportViewer, Silverlight and MVVM. I can imagine if you know what goes where it is really simple but I am unable to get any data shown in my report from my ViewModel.

    I have a report with no datasource, and set the DataContext of the Report Viewer to my Model which is an ObservableCollection of a class with Properties. I then also created a Binding on the TextBlock in the Report to a string of the Property. Pretty much what you would do in a normal RadGridView.

    Thanks,
    Anton

  8. Peter
    Admin
    Peter avatar
    1592 posts
    Member since:
    Sep 2012

    Posted 31 May 2011 Link to this post

    Hello Anton,

    For now Telerik Reports reside on the server and the Silverlight ReportViewer always requires the Telerik Reporting WCF Service, which acts as a communication interface between the client (Silverlight) and the report server. Currently the reporting engine is not compatible with Silverlight and it requires .NET framework to perform its operations. Thus the report can't utilize the Silverlight's DataContext but instead rely on the datasource components that are defined in the report definition.

    You may find useful the following help resources:


    Anyway we already have a couple of ideas how to improve the integration of the Reporting engine with Silverlight, but due to some limitations of the framework we will stay with the report service for now.

    All the best,
    Peter
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

  9. facundo
    facundo avatar
    1 posts
    Member since:
    Oct 2007

    Posted 02 Feb 2012 Link to this post

    Hello Peter,

    I'm working with the Reporting WCF Services and ReportViewerModel. I want to change an exception error that I get from a WCF service call. The thing is that I have my reports in another server and I'm doing some testing regarding reports service connection, so my test consists in trying to render a report simulating a lost of service connection. Once that happens, I got a big timeout exception inside the Report Designer that I'd like to change to an user-friendly message.

    I've been using the ReportViewerModel.Error property to set my custom message in the service callback, but sometimes the Error property gets override for the original exception message.

    How could I display custom messages inside the report designer?
    How can I handle those types of custom error message?

    Thanks in advance.

    UJazz.

  10. John
    John avatar
    24 posts
    Member since:
    Jun 2013

    Posted 05 Jun in reply to Steve Link to this post

    This approach no longer seems to work.

  11. Stef
    Admin
    Stef avatar
    1373 posts
    Member since:
    Dec 2012

    Posted 10 Jun Link to this post

    Hi John,

    The code should be executed when the ReportViewer is fully loaded in the visual tree.

    Please consider the following example with printing:

      private ReportViewerModel m_viewerModel;
    private ReportViewerModel ViewerModel
    {
        get
        {
            if (m_viewerModel == null && VisualTreeHelper.GetChildrenCount(this.ReportViewer1) > 0)
            {
                var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);
                m_viewerModel = (ReportViewerModel)layoutRoot.DataContext;
            }
            return m_viewerModel;
        }
    }
     
    public MainPage()
    {
        InitializeComponent();
        ReportViewer1.RenderBegin += ReportViewer1_RenderBegin;
    }
     
    void ReportViewer1_RenderBegin(object sender, RenderBeginEventArgs args)
    {
        //parameters passing
        this.ViewerModel.PropertyChanged += this.ViewerModel_PropertyChanged;
    }
     
     
    private void ViewerModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "State" && IsReadyToPrint())
        {
            this.ViewerModel.PropertyChanged -= this.ViewerModel_PropertyChanged;
     
            this.PrintReport();
        }
    }
     
    private bool IsReadyToPrint()
    {
        return this.ViewerModel.State == ReportViewerStates.ViewerPage;
    }
     
    private void PrintReport()
    {
        this.m_viewerModel.PrintReportCommand.Execute(null);
    }

    I hope this helps you.

    All the best,
    Stef
    the Telerik team
     
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
     

Back to Top
DevCraft Release