Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report Viewer Problem

Status
Not open for further replies.

besto1a

Programmer
Aug 20, 2006
41
0
0
GB
I have a problem with the report viewer. I have a form showing a report viewer (RV), When the form loads it shows the report the report viewer is linked to with the data bindings. I want to be able to change the report (rdlc) the RV shows programaticaly but for some reason it does not work, can this be done, or do you need a seperate RV for each individual report??
 
I use the following and it works great for me:

Code:
        Me.rpvReports.ServerReport.ReportPath = "/Everyone/Schenck Dashboard"
        Me.rpvReports.RefreshReport()

I think the .RefreshReport may be the key, unless you already have that then I don't know. Good luck and let us know.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Thanks for the reply

I forgot to add that the reports are not server based, they are held within the application.

 
I don't believe your question, and Refresh Report have any bearing on each other. Refresh only refreshes the records on the current report, it does not change the report source, or report name. If you want to change the name of the report being displayed, modify the ReportSource property from the calling form. If you want to change the report being shown, after the viewer is open, you will need to add that functionality to the Viewer form. Whichever way you go, it is not necessary to have a separate Viewer form for each report, and you can choose to open multiple copies of the same viewer, each with different reports (or duplicates of the same report), or you can choose to have only one viewer active at a time. You would control this with the use (or omission of) the New keyword when creating and opening the viewer form.
 
I have a similar situation... where i have multiple reports (rdlc) and one viewer. i want to be able to change the report 'source' for the viewer depending on where the viewer is called from. I use the following:

Me.ReportViewer.Reset()
Me.ReportViewer.LocalReport.ReportEmbeddedResource = "Application.PropertyAppointments.rdlc"

Me.ReportViewer.RefreshReport()

but it still gives me an error about the datasource for the report viewer.. any ideas?

thanks
 
If your reports are compiled into the application, you can create instances of them, similar to this:

Code:
Private Sub btnReport1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport1.Click
  dim oRpt as new Report1

  [green]' report formatting code can go here[/green]
  
  ReportViewer.ReportSource = oRpt
  ReportViewer.Refresh()
End Sub


Private Sub btnReport2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport2.Click
  dim oRpt as new Report2

  [green]' report formatting code can go here[/green]
  
  ReportViewer.ReportSource = oRpt
  ReportViewer.Refresh()
End Sub

You can also change the datasource for the report object on the fly this way if you have multiple tables with the same structure.

Hope that helps.

Pat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top