Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Combining Multiple Reports in ReportViwer

Posted on 2009-07-11
18
Medium Priority
?
778 Views
Last Modified: 2012-05-07
Hi, I'm using VB 2005, WinForms. I have an application, wherein I've created a couple of reports for my users to print. I have that part figured out. However, the way I have it set up now, the user would have to go to three different ReportViewers to get all three reports. I'd like to figure out a way to have them go to one ReportViewer and see a "combination of reports."  Is there any way to have all three reports (or any combination thereof) roll into one ReportViewer. If we could have the reports execute in some sort of loop, that would be fine as well.

Thanks,
Fulano
0
Comment
Question by:Mr_Fulano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 4
  • 3
18 Comments
 
LVL 12

Expert Comment

by:rgn2121
ID: 24829539
I don't use ReportViewer, but if it is simialr at all tot he Crystal Report Viewer, then I assume you supply a datasource and load a report?
If that is the case then you would just supply a different report through some sort of selection on the form itself.
For instance, I use the CrystalReportViewer and have designed it so that when the viewer loads it is blank.  There is a drop down that loads every available report and all the user does is make a selection and then click a button and the get they need.  I have about 13 reports being used with the 1 viewer control.
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24829545
Here is a good link if the above didn't help...
http://msdn.microsoft.com/en-us/library/ms251671(VS.80).aspx 
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24829597
Okay...found a little code!  Looks like I have helped someone at work something similar to what I do with CR, only using RV.  Most of this is done through code though, so I am not sure about what to do if you are using the designer.  The link above should help with that.
This was place in the form_load event of the form with the viewer, but you can move it...
A few notes for the code below:
I did a WriteXMLSchema for the ds.Tables("MyTable")

I then right clicked my project and added an existing item and then selected that file. (.xsd)
The NewDataSet_MyDataSet is the name I gave the file that I added to my project...the myTable is the data I am passing it to use.
Without testing, I think you can use this, just changing the report names, to switch reports at runtime.
 


Me.ReportViewer1.Reset() 
Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local 
Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("NewDataSet_MyDataSet", ds.Tables("MyTable"))) 
Me.ReportViewer1.LocalReport.ReportPath = "Report1.rdlc" 'Report has to be in the debug folder or use the full path
Me.ReportViewer1.RefreshReport() 

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 48

Accepted Solution

by:
jpaulino earned 2000 total points
ID: 24829809
Fulano,
You can use SubReports
Check this article  that I have posted on CodeProject  http://www.codeproject.com/KB/vb/MicrosoftReports.aspx
0
 

Author Comment

by:Mr_Fulano
ID: 24831249
Hi rgn2121, thanks for all the hard work, but I already have the reports working. I have 3 reports that provide the user information on specific areas...I simply want to tie them together into 1 report master for something like a Auditor's report book.

' This shows only Report1
What I want to do is something like instead of:  
     frm.ReportViewer1.LocalReport.ReportPath = "../../Report1.rdlc"

' This ties all 3 reports together into a book format.
I would like to do:
     frm.ReportViewer1.LocalReport.ReportPath = "../../Report1.rdlc & Report2.rdlc & Report3.rdlc"

Thanks,
Fulano
0
 

Author Comment

by:Mr_Fulano
ID: 24831267
Hi JPaulino,

WOW...simply WOW!!!  Where was this article when I was learning how to work with ReportViewer...you should work for Microsoft, because this is better than anything I've ever seen come out of their documentation division.

After reading your section on Subreports, I do however have one question...I'm still not sure how to link my 3 "existing" reports together into one master report.

What I want to do is something like what I explained in the post above to Member "rgn2121". I want to tie Report1 to Report2 and to Report3 to make one master report and then show them in ReportVierwer1.

Thanks,
Fulano
0
 

Author Comment

by:Mr_Fulano
ID: 24831527
Here's a a bit more information that might help you both in trying to provide a solution.

I want to place 3 checkboxes on one of my Forms. Each checkbox will handle a different report. So, for example Checkbox1 will handle Report1, and so on...

I want to give the users the choice to print whatever combination of reports they want. So, they may want Reports 1 and 2; or 2 and 3; or 1,2 and 3; or 1 and 3, etc.

I need the code to be able to tie the reports together into one long report and show that in ReportViewer - kind of like chapters in a book to make up a long combined report.

Hope the better explanation helps.

Fulano
0
 

Author Comment

by:Mr_Fulano
ID: 24832648
Hi JPaulino,

I've made some progress...I'm now able to concatenate multiple reports to one ReportViewer by using your idea of Subreports. I'm still having a bit of an issues with reports that have parameters, but I'll figure it out. I'm now going to work on the checkboxes part of the problem and will posts some results.

Basically what I plan to do is just check if the checkboxes.checked property = True, if so, then I'll execute some code to run that particular report. I'd like to automate it as much as possible with a method that will loop through all the checkboxes, check their checked state and then execute some generic code that for which I can pass some parameters, but this will all take some work.

If you have any suggestions, I'm always happy to entertain your ideas.

Thanks for the help,
Fulano
0
 

Author Comment

by:Mr_Fulano
ID: 24833543
Hi JPaulino,

OK, here's a total 180 reversal for you...I now have ALL my reports concatenating into one report with the Button4 code in the snippet below:

Now lets say I want to hide one of the reports. -- Remember I want to give my users the ability to include the report or not to include them. However, this code does not allow for that. It simply includes everything you have as a sub report.

Is there a way that I can control which subreports are included and which ones are not?

I tried the following code in the Button4_Click event, but it had no effect:

Dim ReportSource1 As New ReportDataSource("subreport1", m_dt)
Dim ReportSource2 As New ReportDataSource("subreport2", m_dt)

frm.ReportViewer1.LocalReport.DataSources.Add(ReportSource1)
frm.ReportViewer1.LocalReport.DataSources.Add(ReportSource2)

Any suggestions?

Fulano
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim frm As New Form5
frm.ReportViewer1.Reset()
frm.ReportViewer1.LocalReport.ReportPath = "../../Report4.rdlc"
frm.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_DataTable2", m_dt))
AddHandler frm.ReportViewer1.LocalReport.SubreportProcessing, AddressOf Me.SubreportProcessingEventHandler
frm.ShowDialog()
End Sub
'===================
Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
Dim ReportSource As New ReportDataSource("DataSet1_DataTable2", m_dt)
e.DataSources.Add(ReportSource)
End Sub

Open in new window

0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24833695
I Fulano,
Sorry I was out yesterday for a wedding ...not mine  :)
What is missing now ? Is just show or hide subreports from the user choice ? I will show you some example later.
0
 

Author Comment

by:Mr_Fulano
ID: 24834805
Hi JPaulion,

...a wedding... wow, you gave up programming for a wedding?!? You must have been dragged out there by the wife or girl-friend (they do things like that)... LOL.

OK, lets recap:

1). I got the ReportViewer to show me as many "pre-created/existing" reports as I want using your SubReport technique. -- Very nice!

2). I can't pass parameter to the SubReports yet, but that may be OK. I don't think I'll need that, because these are Audit reports and an Auditor will want to see everything.

3). I now need to give the users a way to select which reports they want or need to include in their audit report. The reason for this is that they may only need to show reports 1,3 and 7 out of 20 different reports. So, why create a huge audit report book with info they may not need. -- I plan to do this by giving them checkboxes for each report, so they can check off the ones they want. I can add some sort of IF statement to include the report IF the corresponding checkbox is checked.

4). My problem now is I cannot suppress a report. They ALL show. -- So, how can I hide the reports they do not select (assuming we have 20 reports and they only select say...reports 3 and 6).

Thanks,
Fulano
0
 

Author Comment

by:Mr_Fulano
ID: 24834807
BTW, here is my code again. Please see below:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim frm As New Form5
frm.ReportViewer1.Reset()
frm.ReportViewer1.LocalReport.ReportPath = "../../Report4.rdlc"
frm.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_DataTable2", m_dt))
AddHandler frm.ReportViewer1.LocalReport.SubreportProcessing, AddressOf Me.SubreportProcessingEventHandler
frm.ShowDialog()
End Sub
'===================
Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
Dim ReportSource As New ReportDataSource("DataSet1_DataTable2", m_dt)
e.DataSources.Add(ReportSource)
End Sub

Open in new window

0
 

Author Comment

by:Mr_Fulano
ID: 24834911
Hi JPaulino,

One last thing...in the Subreport's "Visibility" properties, there's a checbox that says: "Visibility can be toggled by another report Item".

What does that mean? Can I have a parameter in the Main Report that tells each Subreport to be visible or not to be visible? My option is disabled, how can I get that to work, if you think that may be an option?

Thanks,
Fulano
0
 

Author Comment

by:Mr_Fulano
ID: 24835458
OK...stop the presses...I think I got it!

See the link below for a good solution:
http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/6b764303-083d-45d9-9a9b-c4e5d6d5bacd/

From that link I quote:
>> "You have one report "ParentReport". You also have another report "ChildReport". In the parent report, you add a subreport ("subreport1") with its subreport property set to "ChildReport".  You then add a parameter to the parent report: "subReportHidden" as a boolean. You then set the "Hidden" sub property in the "Visibility" property of subreport1 to the expression "=Parameters!subReportHidden.Value".

In the winform code, you add the following code to select the subreport1 visibility:"<<

See the code below:

It works!

I'll leave this open in case you have some thoughts or inprovements to share.
Fulano
'This hides the report - 
Dim p As New ReportParameter("subReportHidden", "False")
frm.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {p})
frm.ReportViewer1.LocalReport.Refresh()
 
'This shows the report -
Dim p As New ReportParameter("subReportHidden", "True")
frm.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {p})
frm.ReportViewer1.LocalReport.Refresh()

Open in new window

0
 

Author Comment

by:Mr_Fulano
ID: 24835536
Here's the code for the checkbox option. If the checkbox is checked then the subreport is show, if the checkbox is unchecked the report is suppressed.


Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim frm As New Form5
frm.ReportViewer1.Reset()
frm.ReportViewer1.LocalReport.ReportPath = "../../Report4.rdlc"
frm.ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_DataTable2", m_dt))
AddHandler frm.ReportViewer1.LocalReport.SubreportProcessing, AddressOf Me.SubreportProcessingEventHandler
 
' Shows the subreport IF the checkbox is checked.
Dim p As New ReportParameter("subReportHidden", Not (CheckBox1.Checked))
frm.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {p})
frm.ReportViewer1.LocalReport.Refresh()
 
frm.ShowDialog()
End Sub

Open in new window

0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24837700
...a wedding... wow, you gave up programming for a wedding?!? You must have been dragged out there by the wife or girl-friend (they do things like that)... LOL.

I have tried to take the labtop with me but no luck :(
Well, that's the way to hide controls inside the report. Nice you have figured out. Ignore No suggestions

Dim p As New ReportParameter("subReportHidden", "False")
frm.ReportViewer1.LocalReport.SetParameters(p)
frm.ReportViewer1.LocalReport.Refresh()

Open in new window

0
 

Author Closing Comment

by:Mr_Fulano
ID: 31602381
Great article by JPaulino...everyone should read this if you're working with ReportViewer.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24844793
Thanks Fulano,
I will write the second part, with some advanced but useful features soon. Maybe until the end of the week I will post there.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question