Kevin Kilgore
asked on
visual basic 2010 ReportViewer question
I've searched the web but can't find anything that works yet for this question:
I'm creating a report window in my vb 2010 program and give users options to select 2 different reports to run. The ReportViewer Control only let's you run one report at a time. How would i code this so that depending on which report the user selects, the single report viewer control will display the desired report based on user selection?
thanks!
I'm creating a report window in my vb 2010 program and give users options to select 2 different reports to run. The ReportViewer Control only let's you run one report at a time. How would i code this so that depending on which report the user selects, the single report viewer control will display the desired report based on user selection?
thanks!
ASKER
Gotcha...sorry, i'm new to this....on the part where you want me to put in "YourDataSourceInfo", what exactly needs to go there? something like "me.MyDataSet" or "me.MyDataSet.MyBindingSou rce" ? Also, should the "YourReportPath" be in quotations in the code?
thanks!
thanks!
This all depends on how you set up your reportviewer object. Are you dynamically loading your current report by setting the report path in code or did you select the report from the reportviewer control on your form?
Are your reports embedded in your project or are they stored in an external file location (C:|Reports or something)?
How is your current datasource set up?
Are your reports embedded in your project or are they stored in an external file location (C:|Reports or something)?
How is your current datasource set up?
ASKER
At first i selected the report from the reportviewer control on my form but that did me no good since i need to display two reports at will instead of only one. So i took that off...reports are embedded in the project.... on the report window form, i have 1 dataset, 1 table adapter, and 1 binding source....that's all so far....
Ok. You may not need to do anything with the datasource in code since you have it set on the form. Just use this to load different reports for embedded report.rdlc files.
MainReportViewer.LocalRepo rt.ReportE mbeddedRes ource = "YourProjectName.ReportNam e.rdlc"
MainReportViewer.RefreshRe port
If your project is named "Project1" and your report is named "RPT1.rdlc" then it's as simple as that.
MainReportViewer.LocalRepo rt.ReportE mbeddedRes ource = "Project1.RPT1.rdlc"
MainReportViewer.LocalRepo
MainReportViewer.RefreshRe
If your project is named "Project1" and your report is named "RPT1.rdlc" then it's as simple as that.
MainReportViewer.LocalRepo
ASKER
Ok i think we are getting somewhere, i tried the suggestion above and it refreshed the report or at least it changed it to the one i wanted but it didn't generate the report because it had this error message:
"A Data Source Instance has not been supplied for the Data Source "MyReport.rdlc"
"A Data Source Instance has not been supplied for the Data Source "MyReport.rdlc"
ASKER
....meant to say the reportviewer came up with that error message ....
Ok. You just need to set your datasource/bindingsource each time you refresh the control. Whatever you are using that is on your form, we are going to set that in code.
MainReportViewer.LocalRepo rt.DataSou rces.Add(n ew ReportDataSource("DataSour ceName", myBindingSource)
MainReportViewer.LocalRepo rt.ReportE mbeddedRes ource = "YourProjectName.ReportNam e.rdlc"
MainReportViewer.RefreshRe port
MainReportViewer.LocalRepo
MainReportViewer.LocalRepo
MainReportViewer.RefreshRe
ASKER
Ok, so I put the code in but it is underlining the "ReportDataSource" part and saying "Report Data Source is not definied"....Am I doing something wrong? Here is my code:
ReportViewer1.LocalReport. DataSource s.Add(new ReportDataSource("area51DataSet", InventoryBindingSource)Rep ortViewer1 .LocalRepo rt.ReportE mbeddedRes ource = "Area_51.r_SerialID.rdlc"
ReportViewer1.RefreshRepor t()
I have attached the actual code so you can see....
error-code.JPG
ReportViewer1.LocalReport.
ReportViewer1.RefreshRepor
I have attached the actual code so you can see....
error-code.JPG
Add this to the top of your code page.
Imports Microsoft.Reporting.Winfor ms
OR
Add Microsoft.Reporting.Winfor ms. before Reportdatasource.
Imports Microsoft.Reporting.Winfor
OR
Add Microsoft.Reporting.Winfor
ASKER
Tried both, still getting same error...i've attached what my form looks like and the code behind it...maybe that will help a little...thanks!
Public Class w_ReportCenter
Private Sub w_ReportCenter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'area51DataSet.Inventory' table. You can move, or remove it, as needed.
Me.InventoryTableAdapter.Fill(Me.area51DataSet.Inventory)
Me.ReportViewer1.RefreshReport()
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub btnRetrieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetrieve.Click
If cboArea.Text = "Inventory" And cboReport.Text = "Master Report" Then
ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("area51DataSet", InventoryBindingSource))
ReportViewer1.LocalReport.ReportEmbeddedResource = "Area_51.r_SerialID.rdlc"
ReportViewer1.RefreshReport()
End If
End Sub
End Class
form.JPG
ASKER
I also left the coding out of the combo boxes so it wouldn't crowd the code i just gave you since it was a larger portion of code...just loading lists in the combo boxes...
Sorry for the delay. Busy few days.
Can you take a screenshot of the data schema that is shown when you are viewing the rdlc designer? We may have to recreate your reportviewer object. We are trying to dynamically assign items but the way it is set up there on your form is a static method. I would just like to see what is available to the report in the report designer.
Can you take a screenshot of the data schema that is shown when you are viewing the rdlc designer? We may have to recreate your reportviewer object. We are trying to dynamically assign items but the way it is set up there on your form is a static method. I would just like to see what is available to the report in the report designer.
ASKER
Is this the right screen you are referring to?
project.PNG
project.PNG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the info, I'll try this as soon as I get back to town today
Great! What was your final code?
Something like this....
MainReportViewer.LocalRepo
MainReportViewer.LocalRepo
'Add any parameters you have
MainReportViewer.RefreshRe