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

Hosting ReportViewer in WPF

4 Answers 509 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sid
Top achievements
Rank 1
Sid asked on 16 Jun 2009, 07:07 PM
I'm trying to display a report in a WPF window and I'm stuck.

I know I had something similar working a while back but with the changes I've made and upgrade to the Telerik ReportViewer I can't seem to accomplish the task now.

Here's the code for my ReportViewer window:

    public partial class MyReportViewer : Window  
    {  
        private IReportDocument myReport;  
 
        public MyReportViewer(IReportDocument document)  
        {  
            myReport = document;  
            InitializeComponent();  
        }  
 
        private void WindowLoaded(object sender, RoutedEventArgs e)  
        {  
            System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();  
 
            ReportViewer rptViewer = new ReportViewer();  
            rptViewer.Report = this.myReport;  
            rptViewer.RefreshReport();  
            host.Child = rptViewer;  
              
              
        }  
   }  

 

 

 



Here's the calling window:
...

 

            KeyFront keyfront = new KeyFront(zone.ZoneID);  
            MyReportViewer rptViewer = new MyReportViewer(keyfront);  
            rptViewer.Show(); 

Here's the report code:
 

        public KeyFront(int zonepk)  
        {  
            /// <summary>  
            /// Required for telerik Reporting designer support  
            /// </summary>  
            InitializeComponent();  
 
            this.sqlDataAdapter1.SelectCommand.Parameters["@ZonePK"].Value = zonepk;  
            this.DataSource = this.sqlDataAdapter1;  
 
 
            //  
            // TODO: Add any constructor code after InitializeComponent call  
            //  
        } 

 

 

 

The report viewer window does appear but is blank.  What am I missing?

Thanks,
-Sid Meyers.

 

 

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 17 Jun 2009, 01:44 PM
Hi Sid,

If the viewer is showing, then the problem is most probably related to the report and its datasource. Please make sure that its datasource is properly populated and the report viewer has completely loaded before showing a report in it i.e. you can try setting the report in another control event handler after the viewer has already loaded on the form.
You can also test if hosting this in windows forms works like expected.

Best wishes,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sid
Top achievements
Rank 1
answered on 17 Jun 2009, 02:16 PM
Steve,

I'm sorry, my wording was not chosen very well.  The WPF window appears but not the report viewer.  I've tried stepping through this, but maybe with a fresh start today I might see something I missed.  I'll try the suggestion about putting the report setting in a different control event.

I was wondering if there was something obvious I was missing in my code.

Yes, the datasource is set to sqladapter1.  My zone parameter exists and has a value.  The host.child has the report viewer as an object, the visible property is true.  The report viewer report property is set to my "keyfront" report object.  But, still when the window displays I get a blank window.  I'm trying to figure out if I can see if the sqladapter has data.  I don't see any property as yet which would show this.  I've also tried to load the activity monitor on the sql server.

If by chance you've got any examples of hosting this in WPF or if you can think of anything else it would be greatly appreciated.

Thanks,
-Sid Meyers
0
Accepted
Chavdar
Telerik team
answered on 18 Jun 2009, 08:10 AM
Hi Sid,

I have attached a sample project which illustrates a possible approach to achieve your requirement. Please review it and let me know whether it works as expected.

Kind regards,
Chavdar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Sid
Top achievements
Rank 1
answered on 18 Jun 2009, 02:02 PM
Chavdar,

Perfect!  So it all came down to how I was setting up the WindowsFormHost.  There must be something about how I was trying to declare the host object inside the WindowLoaded event.  It took me a few minutes to resolve an issue that I had declared the "Loaded" event inside the MyReportViewer <Window> section vs. the <my:WindowsFormsHost>, because I was getting a casting error.  Now I can concentrate on trying to build the report selection menus!

Thanks,
-Sid.
Tags
General Discussions
Asked by
Sid
Top achievements
Rank 1
Answers by
Steve
Telerik team
Sid
Top achievements
Rank 1
Chavdar
Telerik team
Share this question
or