This is a migrated thread and some comments may be shown as answers.

Problem getting the ReportViewerModel after upgrade to Q1'11

13 Answers 223 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 16 Mar 2011, 03:16 PM
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

13 Answers, 1 is accepted

Sort by
0
Chavdar
Telerik team
answered on 16 Mar 2011, 04:43 PM
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!
0
Pediatric Computing
Top achievements
Rank 1
answered on 11 May 2011, 04:40 PM
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...
0
Steve
Telerik team
answered on 16 May 2011, 03:04 PM
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
0
Michael
Top achievements
Rank 1
answered on 16 May 2011, 08:11 PM
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

0
Anton Swanevelder
Top achievements
Rank 2
answered on 31 May 2011, 04:28 PM
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
0
Peter
Telerik team
answered on 31 May 2011, 05:26 PM
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
0
facundo
Top achievements
Rank 1
answered on 02 Feb 2012, 10:51 PM
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.

0
John
Top achievements
Rank 1
answered on 05 Jun 2014, 09:12 PM
This approach no longer seems to work.
0
Stef
Telerik team
answered on 10 Jun 2014, 09:46 AM
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 >>
 
0
Michael Hilgers
Top achievements
Rank 1
answered on 18 May 2016, 01:53 PM

Hello everyone,

may it be possible that "(FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);" isn't working any more in 2015 and newer releases? I used this way described in the last post some years, but now with a newer Reporting Version it seems to be broken.

Any advises how to deal with this situation now?

Regards,

Michael

0
Stef
Telerik team
answered on 20 May 2016, 10:22 AM
Hi Michael,

The WPF|Silverlight ReportViewer control's ReportViewerModel is for internal usage only, but you can use the exposed viewer's API to perform the same tasks - WPF ReportViewer Members and Silverlight ReportViewer Members.

If you are missing a functionality from the ReportViewerModel, please let us know.


In addition, please check the updated approach for configuring the WPF|Silverlight ReportViewer in an application - WPF ReportViewer: Manual Setup and Silverlight ReportViewer: Setup.

Regards,
Stef
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Michael Hilgers
Top achievements
Rank 1
answered on 23 May 2016, 06:04 AM

Hello Stef, 

thx for your reply. I already reviewed the Silverlight ReportViewer members, but no one of them can perform what is performed by the code i've posted. The most obvious was the "RefreshReport", but using this absolutly nothing happens ;)

So i didn't found a way of reproducing my functionality with the current available members of the ReportViewer.

Do you see a way how to do this?

Regards,

Michael

0
Stef
Telerik team
answered on 25 May 2016, 04:06 PM
Hello Michael,

I am missing the whole context and where the given code snippet for hiding the parameters area is used, but I can suggest you the following:
  1. Use custom UI like Button that hides the viewer's parameters area;
  2. Use a viewer's event like RenderingEnd to hide the parameters area:
    Private Sub ReportViewer1_RenderingEnd(sender As Object, e As EventArgs)
        ReportViewer1.ParametersAreaVisible = False
    End Sub
 In order to provide you more accurate suggestions, please elaborate on the scenario and the usage of the code snippet.

Regards,
Stef
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Michele
Top achievements
Rank 2
Answers by
Chavdar
Telerik team
Pediatric Computing
Top achievements
Rank 1
Steve
Telerik team
Michael
Top achievements
Rank 1
Anton Swanevelder
Top achievements
Rank 2
Peter
Telerik team
facundo
Top achievements
Rank 1
John
Top achievements
Rank 1
Stef
Telerik team
Michael Hilgers
Top achievements
Rank 1
Share this question
or