none
Loading a reportviewer with a local report RRS feed

  • Question

  • I have a function that returns a local report. However I can't figure out how to take that and load it into a reportviewer.

    So I have a function

    Public Function CreateReport() as LocalReport

    ~do something to create a localreport

    End Function

    So how do I get that so that another form with Reportviewer loads into it.

    • Moved by Mike Feng Monday, January 30, 2012 9:38 AM Report (From:Visual Basic General)
    Friday, January 27, 2012 7:27 PM

Answers

  • I think there's some confusion here I'm not trying to create an .rdlc object. I have several complex reports that have several parameters and data sources each. I have to use these reports in a couple of different ways in one I run the same report multiple times with different variables creating a report each time and them saving all those reports to a pdf automatically, I also have to be able to load the report into a reportviewer. Right now I have the same basic code in two different places and i want to simplify.

    So in what I want to do is take the following code and make it work with a report viewer.

    Public Function BuildReport(ByRef _localreport as LocalReport)

    _localreport.ReportEmbeddedResource = nameofmyreport

    'Code that enters the reports parameters and datasource
    End Function

     

    Again this function works perfectly and it gives me a localreport built just the way I want to. Now what I want to do and haven't been able to figure out is how to take this local report and put it into the reportviewer. So if I take the following code

    Dim my_local_report as New LocalReport

    BuildReport(my_local_report)

    Reportviewer.localreport = my_local_report 'this obviously doesn't work but I'm just trying to show what I want.

    Any input would be welcome and appreciated

    • Marked as answer by BrownRR Tuesday, January 31, 2012 5:45 PM
    Sunday, January 29, 2012 11:09 PM

All replies

  • You can create a reportviewer at design time. You will probably include it in a form.

    If the reportviewer is RV :

    RV.LocalReport.ReportEmbeddedResource = nameOfYourReport
    
    

    In addition, you will have to include a DataSource

    RV.LocalReport.DataSources.Clear()
    RV.LocalReport.DataSources.Add(yourDataSource)
    
    

    And possibly parameters :

    RV.LocalReport.SetParameters(yourParameters)
    
    

    Then start it

    RV.RefreshReport()
    
    

    Sunday, January 29, 2012 4:49 PM
  • Thats not the question I'm asking though. How do I get RV.LocalReport = LocalReportcreatedbyFunction.
    Sunday, January 29, 2012 5:34 PM
  • By its name ?
    Sunday, January 29, 2012 7:35 PM
  • @Sygrien - can you show an example of code where a function that returns a LocalReport object can be set to the report viewer's local report?  A path is no good when you have an object in memory ready to use.  I think the OP is aware that you can set the ReportPath property if a report object is saved to file.

    I did a little looking around and I could not find an answer to this -- there were a few people asking but no one had a real answer.

    @BrownRR:  is it critical that you use a function-returned object in this scenario?  Is it feasable to have .rdlc objects saved in the project folder system?

    Sunday, January 29, 2012 7:46 PM
  • I think there's some confusion here I'm not trying to create an .rdlc object. I have several complex reports that have several parameters and data sources each. I have to use these reports in a couple of different ways in one I run the same report multiple times with different variables creating a report each time and them saving all those reports to a pdf automatically, I also have to be able to load the report into a reportviewer. Right now I have the same basic code in two different places and i want to simplify.

    So in what I want to do is take the following code and make it work with a report viewer.

    Public Function BuildReport(ByRef _localreport as LocalReport)

    _localreport.ReportEmbeddedResource = nameofmyreport

    'Code that enters the reports parameters and datasource
    End Function

     

    Again this function works perfectly and it gives me a localreport built just the way I want to. Now what I want to do and haven't been able to figure out is how to take this local report and put it into the reportviewer. So if I take the following code

    Dim my_local_report as New LocalReport

    BuildReport(my_local_report)

    Reportviewer.localreport = my_local_report 'this obviously doesn't work but I'm just trying to show what I want.

    Any input would be welcome and appreciated

    • Marked as answer by BrownRR Tuesday, January 31, 2012 5:45 PM
    Sunday, January 29, 2012 11:09 PM
  • Honestly, this question would be much better served in the VS Report Controls forum:  http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/threads

    @Moderators:  Please move if you agree.

    • Proposed as answer by Mike Feng Monday, January 30, 2012 9:37 AM
    • Unproposed as answer by Mike Feng Monday, January 30, 2012 9:37 AM
    Sunday, January 29, 2012 11:28 PM